Author Topic: Problems with interrupt 1Ah  (Read 5297 times)

Offline yoran

  • Jr. Member
  • *
  • Posts: 19
Problems with interrupt 1Ah
« on: September 29, 2019, 09:04:47 AM »
(16 bit NASM bare bones)
I use int 1Ah to get time and date, however the time functions seems to have stopped working for some reason.
My time function:
;I/O: BX = string location
get_time:
   pusha

   mov di, bx

   clc               ;anti bios-bug team
   mov ah, 2      ;BIOS time > bcd
   int 1Ah
   jnc .read

   clc
   mov ah, 2
   int 1Ah

.read:
   mov al, ch         ;hours > integer
   call bcd_to_int
   mov dx, ax         ;save

   mov al,   ch         ;hour
   shr al, 4            ;higher bcd > lower
   and ch, 0Fh         ;1`s
   test byte [fmt_12_24], 0FFh
   jz .twelve_hr

   call .add_digit
   mov al, ch
   call .add_digit
   jmp short .minutes

.twelve_hr:
   cmp dx, 0
   je .midnight

   cmp dx, 10
   jl .twelve_st1

   cmp dx, 12
   jle .twelve_st2

   mov ax, dx
   sub ax, 12
   mov bl, 10
   div bl
   mov ch, ah

   cmp al, 0                        ;1-9 PM
   je .twelve_st1

   jmp short .twelve_st2      ;10-11 PM

.midnight:
   mov al, 1
   mov ch, 2

.twelve_st2:
   call .add_digit               ;modified bcd
.twelve_st1:
   mov al, ch
   call .add_digit

   mov al, ':'
   stosb

.minutes:
   mov al, cl         ;minute
   shr al, 4            ;higher bcd > lower
   and cl, 0Fh         ;1`s
   call .add_digit
   mov al, cl
   call .add_digit

   mov al, ' '
   stosb

   mov si, .hours_format      ;assume 24 hour format
   test byte [fmt_12_24], 0FFh
   jnz .copy

   mov si, .pm_format      ;pm?
   cmp dx, 12                  ;test it!
   jg .copy

   mov si, .am_format      ;no? am!

.copy:
   lodsb
   stosb
   cmp al, 0
   jne .copy

   popa
   ret

.add_digit:
   add al, '0'      ;into ASCII
   stosb               ;string into buffer
   ret

   .hours_format   db 'hours',0
   .am_format       db 'AM',0
   .pm_format       db 'PM',0

However my date function still works so Im guessing it isnt to do with the interrupt itself:
;I/O: BX = string
get_date:
   pusha

   mov di, bx

   clc                  ;anti-bug
   mov ah, 4         ;data from BIOS in BCD
   int 1Ah
   jnc .fmt1_day

   clc
   mov ah, 4         ;BIOS updating
   int 1Ah

.fmt1_day:
   mov ah, dl      ;dd
   call .add_2digits

   mov al, '/'
   stosb               ;d/m seperator

.fmt1_month:
   mov ah,   dh      ;mm
   call .add_2digits

   mov al, '/'
   stosb

.fmt1_century:
   mov ah,   ch      ;??00
   call .add_2digits

.fmt1_year:
   mov ah, cl      ;00??
   call .add_2digits

   mov al, 0
   stosb

   popa
   ret

.add_2digits:
   mov al, ah         ;AH to 2 ASCII dig
   shr al, 4
   call .add_digit
   mov al, ah
   and al, 0Fh
   call .add_digit
   ret

.add_digit:
   add al, '0'
   stosb
   ret


How do I fix the time function?
It will either: leak a bit of the memory and crash or just crash (crash as in stop, behaves like jmp $)

EDIT:
I have added a password function to my OS, after I implemented it the get_time function stopped working.
If I do not enter the password and fall back to my terminal, and then use the time function it DOES work, does this have to do with memory leaks/overflows?
EDIT 2: It also seems to depend on the length of the password, if its 1 char then it doesnt "influence" the time function but if its longer the function stops working.
EDIT 3: After debugging a bit the code seems to get stuck at the call bcd_to_int, it does not reach it nor does it return. The bcd_to_int function itself does work however
« Last Edit: September 29, 2019, 09:27:37 AM by yoran »

Offline avcaballero

  • Full Member
  • **
  • Posts: 132
  • Country: es
    • Abre los Ojos al Ensamblador
Re: Problems with interrupt 1Ah
« Reply #1 on: October 01, 2019, 01:23:50 PM »
Look if this helps

Offline yoran

  • Jr. Member
  • *
  • Posts: 19
Re: Problems with interrupt 1Ah
« Reply #2 on: October 07, 2019, 06:23:42 PM »
Sorry for the late reply but no this does not seem to work. I also switched the place of the function in memory and now the new function in that place seems to be having the problems (it just hangs the system).