You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
112 lines
2.9 KiB
112 lines
2.9 KiB
void print(string); |
|
void* dump_ax_return(input); |
|
|
|
void print(string) |
|
char* string; |
|
{ |
|
#asm |
|
push bp |
|
mov bp,sp |
|
mov si,4[bp] |
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
|
new_print_print: |
|
; Prints string in si |
|
; IN si: zero terminated string to print |
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
|
mov ah, #0xE ; Specify 'int 0x10' 'teletype output' function |
|
; [AL = Character, BH = Page Number, BL = Colour (in graphics mode)] |
|
.new_print_printchar: |
|
lodsb ; Load byte at address SI into AL, and increment SI |
|
test al, al |
|
jz .new_print_done ; If the character is zero (NUL), stop writing the string |
|
int #0x10 ; Otherwise, print the character via 'int 0x10' |
|
jmp .new_print_printchar ; Repeat for the next character |
|
.new_print_done: |
|
|
|
pop bp |
|
#endasm |
|
} |
|
|
|
|
|
void print_stack(argument) |
|
{ |
|
#asm |
|
push bp |
|
mov bp,sp |
|
push ds |
|
push ax |
|
|
|
mov ax, ss |
|
mov ds, ax |
|
mov si,4[bp] |
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
|
print_stack_print: |
|
; Prints string in si |
|
; IN si: zero terminated string to print |
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
|
mov ah, #0xE ; Specify 'int 0x10' 'teletype output' function |
|
; [AL = Character, BH = Page Number, BL = Colour (in graphics mode)] |
|
.print_stack_printchar: |
|
lodsb ; Load byte at address SI into AL, and increment SI |
|
test al, al |
|
jz .print_stack_done ; If the character is zero (NUL), stop writing the string |
|
int #0x10 ; Otherwise, print the character via 'int 0x10' |
|
jmp .print_stack_printchar ; Repeat for the next character |
|
.print_stack_done: |
|
|
|
pop ax |
|
pop ds |
|
pop bp |
|
#endasm |
|
} |
|
|
|
void* dump_ax_return(input) |
|
void* input; |
|
{ |
|
return input; |
|
} |
|
|
|
void dump_ax(input) |
|
void* input; |
|
{ |
|
dump_ax_return(input) |
|
#asm |
|
push bp |
|
mov bp,sp |
|
|
|
pusha ; save registers |
|
mov bx, ax |
|
mov ah, #0xE ; Teletype output |
|
|
|
mov cx, #4 ; 4 nipples in a 16 bit word |
|
.dump_ax_loop: |
|
rol bx, #4 ; rotate to next nipple |
|
mov al, bl ; we copy to al because we need to mask only the low 4 bits |
|
and al, #%1111 ; Do the masking |
|
add al, #48 ; convert to ASCII |
|
cmp al, #57 ; If we are greater than 9 ascii, we add 7 to make digit 10 be represented as 'A' |
|
jbe .dump_ax_skip ; -|- |
|
add al, #7 ; -|- |
|
.dump_ax_skip: ; -|- |
|
int #0x10 ; BIOS call 'output' |
|
loop .dump_ax_loop |
|
|
|
popa ; restore registers |
|
|
|
pop bp |
|
#endasm |
|
} |
|
|
|
void print_newline() |
|
{ |
|
#asm |
|
printCRLF: |
|
mov ah, #0xE |
|
mov al, #13 |
|
int #0x10 |
|
mov al, #10 |
|
int #0x10 |
|
ret |
|
#endasm |
|
}
|
|
|