satpro

Print 8x8 Text

Feb 16th, 2026
3,799
0
Never
2
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
ASM (NASM) 8.23 KB | Source Code | 0 0
  1.  
  2.  
  3.  
  4.  
  5. ; ========================================================================================
  6.  
  7. ; Print8 params                Print (x,y,a)
  8. ; p1: a             ascii     r8        ascii character, 0-255
  9.  
  10.  
  11. align 16
  12. export Print8:             ; print an 8x8 pet 8032 text character @(x,y)
  13.  
  14.   sub rsp, 28h
  15.   mov [rsp+00h], rsi
  16.   mov [rsp+08h], rdi
  17.   mov [rsp+10h], rbx
  18.   mov [rsp+18h], rbp
  19.  
  20. ; ----  Enter  -----
  21.  
  22.  
  23. ; 1. src
  24.  
  25. ; get a ptr to the font data
  26.   mov esi, FONT8$             ; ptr to font sets in emulator ram @ $E000
  27.  
  28. ; get offset to font bitmap data (char# * 8 bytes/char)
  29.   mov ebx, r8d                ; get char#
  30.   shl ebx, 3                  ; mult char# x 8 bytes per char
  31.   add esi, ebx                ; rsi: points to param character's bitmap data
  32.  
  33. ; 2. dst
  34.  
  35.   mov edi, VIDEO$             ; base
  36.  
  37. ; add (x,y) offsets
  38.   mov eax, [CursorX8]         ; get (x)
  39.   mov ebx, [CursorY8]         ; get (y)
  40.  
  41.   shl eax, 2                  ; x-offset = x * 4
  42.   shl ebx, 13                 ; y-offset = y * 2000h
  43.  
  44.   add edi, eax                ; add x-offset to base surface
  45.   add edi, ebx                ; add y-offset to base address
  46.  
  47.   mov ebp, edi                ; copy print address to rowptr
  48.  
  49.   mov r10d, [BGcolor8]        ; get bg color
  50.   mov r11d, [FGcolor8]        ; get fg color
  51.  
  52. ; 3.  -----  the print loop  -----
  53.  
  54.   mov dl, 8                   ; init rowctr (8 rows, 8 pixels each)
  55. do8rows:            ; 8-bit processing of one screen row of char data
  56.   mov al, [esi]               ; ax = get bitmap data for 1 screen row (8 pixels, 1 byte)
  57.   mov cl, 8                   ; init pixelctr = 8 pixels per screen row
  58.  
  59. do8pixels:          ; 8 shifts = 1 row (1 byte) of pixel data, poke on 1-bits only
  60.   shl al, 1                   ; shift bit 7 into carry flag
  61.   cmovnc ebx, r10d            ; when bit = 0, use bg color
  62.   cmovc ebx, r11d             ; when bit = 1, use fg color
  63.  
  64.   mov [edi], ebx              ; poke the color to surface memory
  65.  
  66.   add edi, 4                  ; advance to next x-pixel (right 1)
  67.   dec cl                      ; pixelctr = pixelctr-1
  68.   jnz < do8pixels             ; loop until pixelctr = 0
  69.  
  70. ; re-sync the pointers for the next row (down 1)
  71.   add esi, 1                  ; advance fontptr to next source row (+pitch = 1 byte)
  72.   add ebp, 2000h              ; rowptr + pitch = next row
  73.   mov edi, ebp                ; copy rowptr to colptr
  74.   dec dl                      ; rowctr = rowctr-1
  75.   jnz < do8rows               ; loop until rowctr = 0
  76.  
  77.   add D[CursorX8], 8          ; get CursorX8 ready for next Print: +8 pixels
  78.  
  79.  
  80. ; -----  Exit  -----
  81.  
  82.   mov rsi, [rsp+00h]
  83.   mov rdi, [rsp+08h]
  84.   mov rbx, [rsp+10h]
  85.   mov rbp, [rsp+18h]
  86.   add rsp, 28h
  87.   ret
  88.  
  89. ; ========================================================================================
  90.  
  91. ; Plot8(x,y)
  92.  
  93. ; p1: x
  94. ; p2: y
  95.  
  96. align 16
  97. export Plot8:
  98.  
  99.   mov [CursorX8], r8d
  100.   mov [CursorY8], r9d
  101.  
  102.   ret
  103.  
  104. ; ========================================================================================
  105.  
  106. ; SetTextColor8(bg_color,fg_color)
  107.  
  108. ; p1: bg color
  109. ; p2: fg color
  110.  
  111. align 16
  112. export SetTextColor8:
  113.  
  114.   mov [BGcolor8], r8d
  115.   mov [FGcolor8], r9d
  116.  
  117.   ret
  118.  
  119. ; ========================================================================================
  120.  
  121. ; SetFont8(font_num)
  122.  
  123. ; p1: font# (0 = serif, 1 = sans)
  124.  
  125. align 16
  126. export SetFont8:
  127.  
  128.   mov [FontNum8], r8d
  129.  
  130.   ret
  131.  
  132. ; ========================================================================================
  133.  
  134. ; String8           String8 (x,y,pStringz)
  135. ; p1: pStringz      r8        ptr to text string
  136.  
  137. align 16
  138. export String8:            ; String prints a 0-term ascii string
  139.  
  140.   sub rsp, 18h
  141.   mov [rsp+00h], rsi          ; preserve
  142.   mov [rsp+08h], rbx          ; preserve
  143.  
  144. ; -----  Enter  -----
  145.  
  146. ; loop to print a 0-term string
  147.   mov esi, r8d                ; copy of the string ptr
  148.   xor ebx, ebx                ; init string length index = 0
  149.  
  150. strloop8:
  151.   movzx r8d, B[esi + ebx]     ; get a character from the string (r8 = param for Print)
  152.   or r8d, r8d                 ; check to see if character = 0
  153.   jz > strExit8               ; if yes, exit
  154.  
  155.   call Print8                 ; print the character in r8
  156.  
  157.   inc ebx                     ; increment string length index
  158.   jnz < strloop8              ; always loop back for more
  159.  
  160.  
  161. ; -----  Exit  -----
  162.  
  163. strExit8:
  164.   mov rsi, [rsp+00h]          ; restore
  165.   mov rbx, [rsp+08h]          ; restore
  166.   add rsp, 18h
  167.  
  168.   ret
  169.  
  170. ; ========================================================================================
  171.  
  172. ; Print8DecD (n)
  173. ; p1: n             x         r8        
  174.  
  175. align 16
  176. export Print8DecD:
  177.  
  178.   sub rsp, 18h
  179.  
  180.   mov [rsp+00h], rsi          ; save (x) for String16
  181.   mov [rsp+08h], rdi          ; save (y) for String16
  182.   mov [rsp+10h], rbx
  183.  
  184. ; ----- ENTER -----
  185.  
  186.  
  187.   lea edi, textBuffer + 15    ; Point RDI to the last byte of the buffer
  188.   mov B[edi], 0               ; Null-terminate the string
  189.   dec edi                     ; Move to the previous byte
  190.   mov ebx, 10                 ; Divisor for base-10 conversion
  191.   mov eax, r8d                ; number to convert (can be any unsigned 32-bit value)
  192.  
  193. ; Handle the special case of 0
  194.   test eax, eax
  195.   jnz > convert_loop8
  196.   mov B[rdi], '0'
  197.   jmp > donep8
  198.  
  199. convert_loop8:
  200.   xor edx, edx                ; Clear EDX for division (EDX:EAX / EBX)
  201.   div ebx                     ; EAX = EAX / 10, EDX = remainder (0-9)
  202.   add dl, '0'                 ; Convert remainder to ASCII
  203.   mov [edi], dl               ; Store ASCII digit
  204.   dec edi                     ; Move backward in buffer
  205.   test eax, eax
  206.   jnz < convert_loop8         ; Repeat if quotient is not zero
  207.  
  208. donep8:
  209.   inc edi                     ; RDI now points to the first digit
  210. ; At this point, RDI points to the start of the null-terminated string in textBuffer
  211.  
  212. ; Print the string
  213.   mov r8d, edi                ; ptr to number string
  214.   call String8                ; print the string
  215.  
  216.  
  217. ; ----- EXIT -----
  218.  
  219.   mov rsi, [rsp+00h]
  220.   mov rdi, [rsp+08h]
  221.   mov rbx, [rsp+10h]
  222.  
  223.   add rsp, 18h                ; fix the stack
  224.   ret
  225.  
  226. ; ========================================================================================
  227.  
  228. ; Print8HexB (n)
  229. ; p1: n             r8
  230.  
  231. align 16
  232. export Print8HexB:
  233.  
  234.   call dw2hex                 ; convert to an ascii string
  235.  
  236.   lea r8d, textBuffer+6       ; address of the number as a text string
  237.   call String8                ; print the number
  238.  
  239.   ret
  240.  
  241. ; ========================================================================================
  242.  
  243. ; Print8HexW (n)
  244. ; p1: n             r8
  245.  
  246. export align 16
  247. Print8HexW:
  248.  
  249.   call dw2hex                 ; convert to an ascii string
  250.  
  251.   lea r8d, textBuffer+4       ; address of the number as a text string
  252.   call String8                ; print the number
  253.  
  254.   ret
  255.  
  256. ;=========================================================================
  257.  
  258. ; Print8HexD (n)
  259. ; p1: n             r8
  260.  
  261. align 16
  262. export Print8HexD:
  263.  
  264.   call dw2hex                 ; convert to an ascii string
  265.  
  266.   lea r8d, textBuffer         ; address of the number as a text string
  267.   call String8                ; print the number
  268.  
  269.   ret
  270.  
  271. ;=========================================================================
  272.  
  273. ; Print8BinB (n)
  274. ; p1: n             r8
  275.  
  276. align 16
  277. export Print8BinB:
  278.  
  279.   call dw2bin                 ; convert to an ascii string
  280.  
  281.   lea r8d, textBuffer+24      ; address of the number as a text string
  282.   call String8                ; print the number
  283.  
  284.   ret
  285.  
  286. ;=========================================================================
  287.  
  288. ; Print8BinW (n)
  289. ; p1: n             r8
  290.  
  291. align 16
  292. export Print8BinW:
  293.  
  294.   call dw2bin                 ; convert to an ascii string
  295.  
  296.   lea r8, textBuffer+16       ; address of the number as a text string
  297.   call String8                ; print the number
  298.  
  299.   ret
  300.  
  301. ;=========================================================================
  302.  
  303. ; Print8BinD (n)
  304. ; p1: n             r8
  305.  
  306. align 16
  307. export Print8BinD:
  308.  
  309.   call dw2bin                 ; convert to an ascii string
  310.  
  311.   lea r8, textBuffer          ; address of the number as a text string
  312.   call String8                ; print the number
  313.  
  314.   ret
  315.  
  316. ;=========================================================================
  317.  
  318.  
Advertisement