Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ; ========================================================================================
- ; Print8 params Print (x,y,a)
- ; p1: a ascii r8 ascii character, 0-255
- align 16
- export Print8: ; print an 8x8 pet 8032 text character @(x,y)
- sub rsp, 28h
- mov [rsp+00h], rsi
- mov [rsp+08h], rdi
- mov [rsp+10h], rbx
- mov [rsp+18h], rbp
- ; ---- Enter -----
- ; 1. src
- ; get a ptr to the font data
- mov esi, FONT8$ ; ptr to font sets in emulator ram @ $E000
- ; get offset to font bitmap data (char# * 8 bytes/char)
- mov ebx, r8d ; get char#
- shl ebx, 3 ; mult char# x 8 bytes per char
- add esi, ebx ; rsi: points to param character's bitmap data
- ; 2. dst
- mov edi, VIDEO$ ; base
- ; add (x,y) offsets
- mov eax, [CursorX8] ; get (x)
- mov ebx, [CursorY8] ; get (y)
- shl eax, 2 ; x-offset = x * 4
- shl ebx, 13 ; y-offset = y * 2000h
- add edi, eax ; add x-offset to base surface
- add edi, ebx ; add y-offset to base address
- mov ebp, edi ; copy print address to rowptr
- mov r10d, [BGcolor8] ; get bg color
- mov r11d, [FGcolor8] ; get fg color
- ; 3. ----- the print loop -----
- mov dl, 8 ; init rowctr (8 rows, 8 pixels each)
- do8rows: ; 8-bit processing of one screen row of char data
- mov al, [esi] ; ax = get bitmap data for 1 screen row (8 pixels, 1 byte)
- mov cl, 8 ; init pixelctr = 8 pixels per screen row
- do8pixels: ; 8 shifts = 1 row (1 byte) of pixel data, poke on 1-bits only
- shl al, 1 ; shift bit 7 into carry flag
- cmovnc ebx, r10d ; when bit = 0, use bg color
- cmovc ebx, r11d ; when bit = 1, use fg color
- mov [edi], ebx ; poke the color to surface memory
- add edi, 4 ; advance to next x-pixel (right 1)
- dec cl ; pixelctr = pixelctr-1
- jnz < do8pixels ; loop until pixelctr = 0
- ; re-sync the pointers for the next row (down 1)
- add esi, 1 ; advance fontptr to next source row (+pitch = 1 byte)
- add ebp, 2000h ; rowptr + pitch = next row
- mov edi, ebp ; copy rowptr to colptr
- dec dl ; rowctr = rowctr-1
- jnz < do8rows ; loop until rowctr = 0
- add D[CursorX8], 8 ; get CursorX8 ready for next Print: +8 pixels
- ; ----- Exit -----
- mov rsi, [rsp+00h]
- mov rdi, [rsp+08h]
- mov rbx, [rsp+10h]
- mov rbp, [rsp+18h]
- add rsp, 28h
- ret
- ; ========================================================================================
- ; Plot8(x,y)
- ; p1: x
- ; p2: y
- align 16
- export Plot8:
- mov [CursorX8], r8d
- mov [CursorY8], r9d
- ret
- ; ========================================================================================
- ; SetTextColor8(bg_color,fg_color)
- ; p1: bg color
- ; p2: fg color
- align 16
- export SetTextColor8:
- mov [BGcolor8], r8d
- mov [FGcolor8], r9d
- ret
- ; ========================================================================================
- ; SetFont8(font_num)
- ; p1: font# (0 = serif, 1 = sans)
- align 16
- export SetFont8:
- mov [FontNum8], r8d
- ret
- ; ========================================================================================
- ; String8 String8 (x,y,pStringz)
- ; p1: pStringz r8 ptr to text string
- align 16
- export String8: ; String prints a 0-term ascii string
- sub rsp, 18h
- mov [rsp+00h], rsi ; preserve
- mov [rsp+08h], rbx ; preserve
- ; ----- Enter -----
- ; loop to print a 0-term string
- mov esi, r8d ; copy of the string ptr
- xor ebx, ebx ; init string length index = 0
- strloop8:
- movzx r8d, B[esi + ebx] ; get a character from the string (r8 = param for Print)
- or r8d, r8d ; check to see if character = 0
- jz > strExit8 ; if yes, exit
- call Print8 ; print the character in r8
- inc ebx ; increment string length index
- jnz < strloop8 ; always loop back for more
- ; ----- Exit -----
- strExit8:
- mov rsi, [rsp+00h] ; restore
- mov rbx, [rsp+08h] ; restore
- add rsp, 18h
- ret
- ; ========================================================================================
- ; Print8DecD (n)
- ; p1: n x r8
- align 16
- export Print8DecD:
- sub rsp, 18h
- mov [rsp+00h], rsi ; save (x) for String16
- mov [rsp+08h], rdi ; save (y) for String16
- mov [rsp+10h], rbx
- ; ----- ENTER -----
- lea edi, textBuffer + 15 ; Point RDI to the last byte of the buffer
- mov B[edi], 0 ; Null-terminate the string
- dec edi ; Move to the previous byte
- mov ebx, 10 ; Divisor for base-10 conversion
- mov eax, r8d ; number to convert (can be any unsigned 32-bit value)
- ; Handle the special case of 0
- test eax, eax
- jnz > convert_loop8
- mov B[rdi], '0'
- jmp > donep8
- convert_loop8:
- xor edx, edx ; Clear EDX for division (EDX:EAX / EBX)
- div ebx ; EAX = EAX / 10, EDX = remainder (0-9)
- add dl, '0' ; Convert remainder to ASCII
- mov [edi], dl ; Store ASCII digit
- dec edi ; Move backward in buffer
- test eax, eax
- jnz < convert_loop8 ; Repeat if quotient is not zero
- donep8:
- inc edi ; RDI now points to the first digit
- ; At this point, RDI points to the start of the null-terminated string in textBuffer
- ; Print the string
- mov r8d, edi ; ptr to number string
- call String8 ; print the string
- ; ----- EXIT -----
- mov rsi, [rsp+00h]
- mov rdi, [rsp+08h]
- mov rbx, [rsp+10h]
- add rsp, 18h ; fix the stack
- ret
- ; ========================================================================================
- ; Print8HexB (n)
- ; p1: n r8
- align 16
- export Print8HexB:
- call dw2hex ; convert to an ascii string
- lea r8d, textBuffer+6 ; address of the number as a text string
- call String8 ; print the number
- ret
- ; ========================================================================================
- ; Print8HexW (n)
- ; p1: n r8
- export align 16
- Print8HexW:
- call dw2hex ; convert to an ascii string
- lea r8d, textBuffer+4 ; address of the number as a text string
- call String8 ; print the number
- ret
- ;=========================================================================
- ; Print8HexD (n)
- ; p1: n r8
- align 16
- export Print8HexD:
- call dw2hex ; convert to an ascii string
- lea r8d, textBuffer ; address of the number as a text string
- call String8 ; print the number
- ret
- ;=========================================================================
- ; Print8BinB (n)
- ; p1: n r8
- align 16
- export Print8BinB:
- call dw2bin ; convert to an ascii string
- lea r8d, textBuffer+24 ; address of the number as a text string
- call String8 ; print the number
- ret
- ;=========================================================================
- ; Print8BinW (n)
- ; p1: n r8
- align 16
- export Print8BinW:
- call dw2bin ; convert to an ascii string
- lea r8, textBuffer+16 ; address of the number as a text string
- call String8 ; print the number
- ret
- ;=========================================================================
- ; Print8BinD (n)
- ; p1: n r8
- align 16
- export Print8BinD:
- call dw2bin ; convert to an ascii string
- lea r8, textBuffer ; address of the number as a text string
- call String8 ; print the number
- ret
- ;=========================================================================
Advertisement