Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ; part of Nova's experimental OS
- %macro XY_SlideEDI 2
- add EDI %1 + ( %2 * 320 )
- %endmacro
- PlotText: ; Prints a string onto the screen in the cute font
- .loop1: mov al, [esi] ; Fetch the current character
- cmp al, 0 ; This routine fails when I don't do this compare right here
- jz .exit ; And if it's null, then abort the loop
- inc esi ; The next iteration will read the next string character
- push esi ; PointToChar and PutMonoTile modify ESI. We're pushing it out of the way so it isn't altered.
- call PointToChar ; Point ESI at the character data now.
- mov bl, dh ; Copy over the color so PutMonoTile knows which one to use
- call PutMonoTile ; Print the character
- pop esi ; Restore ESI's value
- add edi, 8 ; The next string character will be written eight pixels right of the last one
- jmp .loop1 ;
- .exit: ret ;
- PlotText_nomask: ; Prints a string onto the screen in the cute font
- .loop1: mov al, [esi] ; Fetch the current character
- cmp al, 0 ; This routine fails when I don't do this compare right here
- jz .exit ; And if it's null, then abort the loop
- inc esi ; The next iteration will read the next string character
- push esi ; PointToChar and PutMonoTile modify ESI. We're pushing it out of the way so it isn't altered.
- call PointToChar ; Point ESI at the character data now.
- mov bl, dh ; Copy over the color so PutMonoTile knows which one to use
- mov bh, dl
- call PutMonoTile_nomask ; Print the character
- pop esi ; Restore ESI's value
- add edi, 8 ; The next string character will be written eight pixels right of the last one
- jmp .loop1 ;
- .exit: ret ;
- PointToChar: ; Points ESI at an ASCII character specified
- mov esi, CuteFont ; Start at the top of CuteFont
- and eax, 255 ; Only the lowest byte of EAX matters right now
- shl eax, 3 ; Multiply by 8
- add esi, eax ; Offset ESI
- ret ;
- PlotByte:
- ror eax, 4
- call PlotNybble
- rol eax, 4
- call PlotNybble
- ret
- PlotNybble:
- push eax
- push ebx
- push ecx
- push esi
- add edi, 8 ; step to the next char
- and al, $0f
- xor ecx, ecx
- mov cl, al
- add ecx, HexDigits
- mov al, [ecx]
- call PointToChar
- call PutMonoTile_nomask
- pop esi
- pop ecx
- pop ebx
- pop eax
- ret
- PlotWord:
- shl edx, 4
- call .Nyb
- call .Nyb
- call .Nyb
- call .Nyb
- ret
- .Nyb: shr edx, 4
- push edx
- add edi, 8
- mov esi, HexDigits
- xor eax, eax
- mov al, dl
- and al, 0fh
- add esi, eax
- mov al, [esi]
- call PointToChar
- mov bl, 2
- mov bh, 0
- call PutMonoTile_nomask
- pop edx
- ret
- HexDigits: db "0123456789ABCDEF"
- PutMonoTile: ; Instead of wasting space by reading the font with a byte per pixel, we're doing it in 1bpp
- push edi ; Just in case
- mov ch, 8 ; Load our higher counter. We're using it to count rows.
- .loop1: mov cl, 8 ; Load our lower counter, which will count our columns. We will do this for each row.
- mov al, [esi] ; Get the current row in the font
- .loop2: shl al, 1 ; Shift left...
- jnc .skip ; ...which updates carry. I'm essentially doing what Tepples did in NAME to display NES tiles.
- mov [edi], bl ; If carry is zero, the color won't be poked in
- .skip: inc edi ; Next pixel!
- dec cl ; Decrement the column counter
- jnz .loop2 ; If it isn't the last column, then shift again!
- add edi, 312 ; Move down now
- inc esi ; The font is stored with one row per byte. We only need to step the font pointer each row.
- dec ch ; Decrement the row counter
- jnz .loop1 ; If it isn't the last row, go read the next
- pop edi ; Just in case
- ret ;
- PutMonoTile_nomask: ; Instead of wasting space by reading the font with a byte per pixel, we're doing it in 1bpp
- push edi ; Just in case
- mov ch, 8 ; Load our higher counter. We're using it to count rows.
- .loop1: mov cl, 8 ; Load our lower counter, which will count our columns. We will do this for each row.
- mov al, [esi] ; Get the current row in the font
- .loop2: shl al, 1 ; Shift left...
- mov [edi], bh ; Poke background color
- jnc .skip ; ...which updates carry. I'm essentially doing what Tepples did in NAME to display NES tiles.
- mov [edi], bl ; Poke in foreground color if needed
- .skip: inc edi ; Next pixel!
- dec cl ; Decrement the column counter
- jnz .loop2 ; If it isn't the last column, then shift again!
- mov eax, 312 ; If it is, adjust EDI for the next row of pixels
- add edi, eax ; (We can't apparently add a 16bit constant to it)
- inc esi ; The font is stored with one row per byte. We only need to step the font pointer each row.
- dec ch ; Decrement the row counter
- jnz .loop1 ; If it isn't the last row, go read the next
- pop edi ; Just in case
- ret ;
- RectFill: ; Really slow. Humps the stack a lot...
- push ebx ;
- push edx ;
- push edi
- .loop:
- push edi ;
- push eax ;
- push ebx ;
- push ecx ;
- push edx ;
- mov bx, 1 ;
- call OrthiRun ;
- pop edx ;
- pop ecx ;
- pop ebx ;
- pop eax ;
- pop edi ;
- add edi, 320 ;
- dec dx ;
- jnz .loop ;
- pop edi
- pop edx ;
- pop ebx ;
- ret ;
- PositionXY: ; Sets up EDI to point to the pixel the prorammer wants
- mov cx, 16 ; IT LOOKS LIKE YOU'RE TRYING TO DRAW TO THE SCREEN, WANT SOME HELP?
- mov es, cx ; ES, like the 6502's stack pointer, can't be set directly. We're having it go through BX.
- mov edi, MemScreen ; Start at the top-left in EDI
- and eax, 0ffffh ; Get rid of any bits hiding in the upper half of EAX but keep the rest of EAX the same
- add edi, eax ; Offset EDI horizontally by EAX
- mov ax, bx ; Put BX into AX, because the MUL opcode *automatically* uses EAX
- xor ebx, ebx ; Clear out EBX. We're gonna use it to hold ScreenW now
- mov bx, [ScreenW] ; We're gonna multiply by the screen height to get the offset for the Y position
- mul ebx ; Multiply!
- add edi, eax ; Add the vertcial offset to EDI
- ret ; EDI's ready!
- ClearScreenToColor: ; Clears the whole screen to a color specified by the programmer
- mov bx, 16 ; We're gonna be drawing to the screen after this routine, so set up the ES segment for that
- mov es, bx ; ES, like the 6502's stack pointer, can't be set directly. We're having it go through BX.
- mov edi, MemScreen ; Start at the top-left in EDI
- mov cx, 320*200 ; The whole entire freaking screen :D
- mov bx, 1 ; Might as well fill it horizontally
- OrthiRun: ; Meant for horizontal and vertical lines, but works okay for diagonals too
- push edi
- and ebx, 0ffffh ; Get rid of any bits hiding in the upper half of EBX but keep the rest of EBX the same
- .run: mov [es:edi], al ;
- add edi, ebx ;
- dec cx ;
- jnz .run ;
- pop edi ;
- ret ;
- PutIcon: ; Displays an 8 by 8 tile on the screen, with one nybble per pixel
- mov cl, 0 ; Start at column zero
- mov ch, 8 ; We're drawing 8 rows
- .loop1: mov al, [esi] ; Load a byte of the icon
- and al, 0f0h ; The first pixel is encoded in the first nybble
- shr al, 4 ; Shift it over so it maps to the right colors
- mov [edi], al ; Stash it on the screen
- inc edi ; Next pixel on the screen!
- mov al, [esi] ; Fetch the byte again,
- and al, 00fh ; this time for the other nybble!
- mov [edi], al ; Stash it on the screen
- inc edi ; Next pixel on the screen!
- inc esi ; Okay, we wrote two pixels stored in the icon. Time for the next byte
- inc cl ; Next column
- cmp cl, 4 ; 4th byte read in the row?
- jnz .loop1 ; Continue if it isn't
- .loop2: mov cl, 0 ; Reset the columns counter
- add edi, 320-8 ; Move EDI so that it points to where the next line of the icon should go
- dec ch ; Decrement the row counter,
- jnz .loop1 ; and draw another row if there are still rows left.
- ret
- IconTest: ; It's a smiley face!
- db 0ffh,000h,000h,0ffh
- db 0f0h,0eeh,0eeh,00fh
- db 00eh,00eh,0e0h,0e0h
- db 00eh,00eh,0e0h,0e0h
- db 00eh,0eeh,0eeh,0e0h
- db 00eh,00eh,0e0h,0e0h
- db 0f0h,0e0h,00eh,00fh
- db 0ffh,000h,000h,0ffh
- ;db 0ffh,000h,000h,0ffh \ db 0f0h,0eeh,0eeh,00fh \ db 00eh,00eh,0e0h,0e0h \ db 00eh,00eh,0e0h,0e0h \ db 00eh,0eeh,0eeh,0e0h \ db 00eh,00eh,0e0h,0e0h \ db 0f0h,0e0h,00eh,00fh \ db 0ffh,000h,000h,0ffh
- IconEmpty:
- db 000h,000h,000h,000h
- db 000h,000h,000h,000h
- db 000h,000h,000h,000h
- db 000h,000h,000h,000h
- db 000h,000h,000h,000h
- db 000h,000h,000h,000h
- db 000h,000h,000h,000h
- db 000h,000h,000h,000h
- RepeatedlyPokingEAX:
- mov cx, dx
- RepeatedlyPokingEAX_Alt:
- mov [edi], eax
- add edi, 4
- dec cx
- jnz RepeatedlyPokingEAX_Alt
- ret
- ShadowPrint: ; Not size optimized yet
- push cx
- push dx
- mov cx, 5
- .loop: push esi
- push edi
- loop .loop, cx
- mov dh, 007
- pop edi
- sub edi, 1
- pop esi
- call PlotText
- pop edi
- add edi, 1
- pop esi
- call PlotText
- pop edi
- add edi, 320
- pop esi
- call PlotText
- pop edi
- sub edi, 320
- pop esi
- call PlotText
- pop edi
- pop esi
- mov dh, 0x1f
- call PlotText
- pop dx
- pop cx
- ret
- Repeat4InEAX:
- xor ebx, ebx
- mov bl, al
- shl ax, 8
- or ax, bx
- mov bx, ax
- shl ebx, 16
- or eax, ebx
- ret
- PlotSmallChar2:
- push edi
- push esi
- mov ax, 'A'
- shl ax, 1 ; Multiply by 2
- pop esi
- pop edi
- ret
- PlotSmallChar:
- push edi
- push esi
- mov ch, 5
- xor eax, eax
- mov al, [esi]
- cmp al, ' '
- jz .SmallSpace
- sub al, 'A'
- shl ax, 1 ; Multiply by 2
- mov esi, TinyFont1
- add esi, eax
- mov ax, [esi]
- shl ax, 1 ; Skip first bit for now...
- .loop1: mov cl, 3
- .loop2: mov dh, 0x00 ; Foreground
- mov dl, 0x0f ; Background
- mov [edi], dl
- shl ax, 1
- jnc .loop3
- mov [edi], dh
- .loop3: inc edi
- dec cl
- jnz .loop2
- add edi, 320-3
- dec ch
- jnz .loop1
- pop esi
- pop edi
- ret
- .SmallSpace:
- mov ax, 0
- jmp .loop1
- ret
- PlotSmallText:
- .loop: call PlotSmallChar
- inc esi
- add edi, 4
- mov al, [esi]
- cmp al, 0
- jnz .loop
- ret
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement