gbdk-2020 | GameBoy Development Kit |
| download: https://git.y1.nz/archives/gbdk.tar.gz | |
| README | Files | Log | Refs | LICENSE |
commit 0f4eea69007556fc9082e27aa37e9bab50375d8c parent 4f254b7fb54fb2f81ff0621ab62a3f935b5a4836 Author: Toxa <untoxa@mail.ru> Date: Wed, 21 Jul 2021 15:54:58 +0300 usage of constants for LCDC and STAT Diffstat:
| M | gbdk-lib/libc/gb/drawing.s | 3323 | +++++++++++++++++++++++++++++++++++++++---------------------------------------- |
| M | gbdk-lib/libc/gb/drawing_isr.s | 4 | ++-- |
| M | gbdk-lib/libc/gb/fill_rect.s | 130 | ++++++++++++++++++++++++++++++++++++++++---------------------------------------- |
| M | gbdk-lib/libc/gb/font.s | 1202 | +++++++++++++++++++++++++++++++++++++++---------------------------------------- |
| M | gbdk-lib/libc/gb/gb_decompress_tiles.s | 2 | +- |
| M | gbdk-lib/libc/gb/get_addr.s | 4 | ++-- |
| M | gbdk-lib/libc/gb/get_data.s | 214 | ++++++++++++++++++++++++++++++++++++++++---------------------------------------- |
| M | gbdk-lib/libc/gb/get_tile.s | 4 | ++-- |
| M | gbdk-lib/libc/gb/get_xy_t.s | 136 | ++++++++++++++++++++++++++++++++++++++++---------------------------------------- |
| M | gbdk-lib/libc/gb/init_tt.s | 78 | +++++++++++++++++++++++++++++++++++++++--------------------------------------- |
| M | gbdk-lib/libc/gb/input.s | 1123 | +++++++++++++++++++++++++++++++++++++++---------------------------------------- |
| M | gbdk-lib/libc/gb/set_1bit_data.s | 2 | +- |
| M | gbdk-lib/libc/gb/set_data.s | 2 | +- |
| M | gbdk-lib/libc/gb/set_tile.s | 4 | ++-- |
| M | gbdk-lib/libc/gb/set_tile_submap.s | 4 | ++-- |
| M | gbdk-lib/libc/gb/set_xy_t.s | 132 | ++++++++++++++++++++++++++++++++++++++++---------------------------------------- |
16 files changed, 3172 insertions(+), 3192 deletions(-)
diff --git a/gbdk-lib/libc/gb/drawing.s b/gbdk-lib/libc/gb/drawing.s @@ -1,1780 +1,1771 @@ ;; Optimised Drawing library ;; By Jon Fuge (jonny@q-continuum.demon.co.uk) based on original file ;; Updates -;; 990223 Michael Removed mod_col, splitting it up into -;; fg_colour, bg_colour, and draw_mode +;; 990223 Michael Removed mod_col, splitting it up into +;; fg_colour, bg_colour, and draw_mode ;; Note: some optimisations are available with unneded PUSH DE/POP DE's - ;; BANKED: checked - .include "global.s" + ;; BANKED: checked + .include "global.s" - .globl .init_vram - .globl .copy_vram - - .globl .drawing_lcd, .drawing_vbl - .globl .bg_colour, .fg_colour, .draw_mode + .globl .init_vram + .globl .copy_vram + + .globl .drawing_lcd, .drawing_vbl + .globl .bg_colour, .fg_colour, .draw_mode - .M_SOLID = 0x00 - .M_OR = 0x01 - .M_XOR = 0x02 - .M_AND = 0x03 + .M_SOLID = 0x00 + .M_OR = 0x01 + .M_XOR = 0x02 + .M_AND = 0x03 - .if 0 - .M_SOLID = 0x10 - .M_OR = 0x20 - .M_XOR = 0x40 - .M_AND = 0x80 - .endif + ;; Format of mod_col + ;; 7 6 5 4 3 2 1 0 + ;; mode fg bg - ;; Format of mod_col - ;; 7 6 5 4 3 2 1 0 - ;; mode fg bg + .area _DRAW_HEADER (ABS) - .area _DRAW_HEADER (ABS) - - .org 0x70 + .org 0x70 .drawing_bits_tbl:: - .byte 0x80,0x40,0x20,0x10,0x08,0x04,0x02,0x01 - .byte 0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80 - - .org .MODE_TABLE+4*.G_MODE - JP .gmode - - .module Drawing1 - - ;; Data - .area _BSS - ;; Fill style -.style: - .ds 0x01 - ;; Various varibles -.x_s: - .ds 2 -.y_s: - .ds 2 -.delta_x: - .ds 1 -.delta_y: - .ds 1 -.l_inc: - .ds 1 -.l_d: - .ds 2 -.dinc1: - .ds 2 -.dinc2: - .ds 2 -.tx: - .ds 1 -.ty: - .ds 1 - - .area _BASE - ;; Enter graphic mode + .byte 0x80,0x40,0x20,0x10,0x08,0x04,0x02,0x01 + .byte 0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80 + + .org .MODE_TABLE+4*.G_MODE + JP .gmode + + .module Drawing1 + + ;; Data + .area _BSS + ;; Fill style +.style: + .ds 0x01 + ;; Various varibles +.x_s: + .ds 2 +.y_s: + .ds 2 +.delta_x: + .ds 1 +.delta_y: + .ds 1 +.l_inc: + .ds 1 +.l_d: + .ds 2 +.dinc1: + .ds 2 +.dinc2: + .ds 2 +.tx: + .ds 1 +.ty: + .ds 1 + + .area _BASE + ;; Enter graphic mode .gmode:: - DI ; Disable interrupts + DI ; Disable interrupts - ;; Turn the screen off - LDH A,(.LCDC) - BIT 7,A - JR Z,1$ + ;; Turn the screen off + LDH A,(.LCDC) + AND #LCDCF_ON + JR Z,1$ - ;; Turn the screen off - CALL .display_off + ;; Turn the screen off + CALL .display_off 1$: - LD HL,#0x8000+0x10*0x10 - LD DE,#0x1800-0x18*0x10 - LD B,#0x00 - CALL .init_vram ; Init the charset at 0x8000 - - ;; Install interrupt routines - LD BC,#.drawing_vbl - CALL .add_VBL - LD BC,#.drawing_lcd - CALL .add_LCD - - LD A,#72 ; Set line at which LCD interrupt occurs - LDH (.LYC),A - - LD A,#0b01000100 ; Set LCD interrupt to occur when LY = LCY - LDH (.STAT),A - - LDH A,(.IE) - OR #0b00000010 ; Enable LCD interrupt - LDH (.IE),A - - ;; (9*20) = 180 tiles are used in the upper part of the screen - ;; (9*20) = 180 tiles are used in the lower part of the screen - ;; => We have 24 tiles free - ;; We keep 16 at 0x8000->0x80FF, and 8 at 0x9780->97FF - - LD HL,#0x9800 - LD A,#0x10 ; Keep 16 tiles free - LD BC,#12 ; 12 unused columns - LD E,#18 ; 18 lines + LD HL,#0x8000+0x10*0x10 + LD DE,#0x1800-0x18*0x10 + LD B,#0x00 + CALL .init_vram ; Init the charset at 0x8000 + + ;; Install interrupt routines + LD BC,#.drawing_vbl + CALL .add_VBL + LD BC,#.drawing_lcd + CALL .add_LCD + + LD A,#72 ; Set line at which LCD interrupt occurs + LDH (.LYC),A + + LD A,#(STATF_LYC | STATF_LYCF) + LDH (.STAT),A + + LDH A,(.IE) + OR #.LCD_IFLAG ; Enable LCD interrupt + LDH (.IE),A + + ;; (9*20) = 180 tiles are used in the upper part of the screen + ;; (9*20) = 180 tiles are used in the lower part of the screen + ;; => We have 24 tiles free + ;; We keep 16 at 0x8000->0x80FF, and 8 at 0x9780->97FF + + LD HL,#0x9800 + LD A,#0x10 ; Keep 16 tiles free + LD BC,#12 ; 12 unused columns + LD E,#18 ; 18 lines 2$: - LD D,#20 ; 20 used columns + LD D,#20 ; 20 used columns 3$: - LD (HL+),A - INC A - DEC D - JR NZ,3$ - ADD HL,BC - DEC E - JR NZ,2$ - - ;; Turn the screen on - LDH A,(.LCDC) - OR #0b10010001 ; LCD = On - ; BG Chr = 0x8000 - ; BG = On - AND #0b11110111 ; BG Bank = 0x9800 - LDH (.LCDC),A - - LD A,#.G_MODE - LD (.mode),A - - ;; Setup the default colours and draw modes - LD A,#.M_SOLID - LD (.draw_mode),A - LD A,#0x03 ; Black - LD (.fg_colour),A - LD A,#0x00 ; White - LD (.bg_colour),A - - EI ; Enable interrupts - - RET - - ;; Draw a full-screen image at (BC) + LD (HL+),A + INC A + DEC D + JR NZ,3$ + ADD HL,BC + DEC E + JR NZ,2$ + + ;; Turn the screen on + LDH A,(.LCDC) + OR #(LCDCF_ON | LCDCF_BG8000 | LCDCF_BGON) + AND #~LCDCF_BG9C00 ; BG Bank = 0x9800 + LDH (.LCDC),A + + LD A,#.G_MODE + LD (.mode),A + + ;; Setup the default colours and draw modes + LD A,#.M_SOLID + LD (.draw_mode),A + LD A,#0x03 ; Black + LD (.fg_colour),A + LD A,#0x00 ; White + LD (.bg_colour),A + + EI ; Enable interrupts + + RET + + ;; Draw a full-screen image at (BC) .draw_image:: - LD HL,#0x8000+0x10*0x10 - LD DE,#0x1680 - CALL .copy_vram ; Move the charset - RET + LD HL,#0x8000+0x10*0x10 + LD DE,#0x1680 + CALL .copy_vram ; Move the charset + RET - ;; Replace tile data at (B,C) with data at DE and store old value at HL + ;; Replace tile data at (B,C) with data at DE and store old value at HL .switch_data:: - PUSH DE ; Save src - PUSH HL ; Save dst - LD L,B - SLA L - SLA L - SLA L - LD H,#0x00 - ADD HL,HL - LD D,H - LD E,L - - LD HL,#.y_table - SLA C - SLA C - SLA C - LD B,#0x00 - ADD HL,BC - ADD HL,BC - LD A,(HL+) - LD H,(HL) - LD L,A - ADD HL,DE - - LD B,H ; BC = src - LD C,L - POP HL ; HL = dst - PUSH BC ; Save dst - LD A,H - OR L - JR Z,1$ - LD DE,#0x10 - CALL .copy_vram + PUSH DE ; Save src + PUSH HL ; Save dst + LD L,B + SLA L + SLA L + SLA L + LD H,#0x00 + ADD HL,HL + LD D,H + LD E,L + + LD HL,#.y_table + SLA C + SLA C + SLA C + LD B,#0x00 + ADD HL,BC + ADD HL,BC + LD A,(HL+) + LD H,(HL) + LD L,A + ADD HL,DE + + LD B,H ; BC = src + LD C,L + POP HL ; HL = dst + PUSH BC ; Save dst + LD A,H + OR L + JR Z,1$ + LD DE,#0x10 + CALL .copy_vram 1$: - POP HL ; HL = dst - POP BC ; BC = src - LD A,B - OR C - JR Z,2$ - LD DE,#0x10 - CALL .copy_vram + POP HL ; HL = dst + POP BC ; BC = src + LD A,B + OR C + JR Z,2$ + LD DE,#0x10 + CALL .copy_vram 2$: - RET + RET - .area _CODE - ;; Advance the cursor + .area _CODE + ;; Advance the cursor .adv_gcurs:: - PUSH HL - LD HL,#.tx ; X coordinate - LD A,#.MAXCURSPOSX - CP (HL) - JR Z,1$ - INC (HL) - JR 99$ + PUSH HL + LD HL,#.tx ; X coordinate + LD A,#.MAXCURSPOSX + CP (HL) + JR Z,1$ + INC (HL) + JR 99$ 1$: - LD (HL),#0x00 - LD HL,#.ty ; Y coordinate - LD A,#.MAXCURSPOSY - CP (HL) - JR Z,2$ - INC (HL) - JR 99$ + LD (HL),#0x00 + LD HL,#.ty ; Y coordinate + LD A,#.MAXCURSPOSY + CP (HL) + JR Z,2$ + INC (HL) + JR 99$ 2$: - LD (HL),#0x00 + LD (HL),#0x00 99$: - POP HL - RET + POP HL + RET - ;; Draw a circle from (B,C) with radius D + ;; Draw a circle from (B,C) with radius D .circle:: - LD A,B ;Store center values - LD (.x_s),A - LD A,C - LD (.y_s),A - - XOR A - LD (.x_s+1),A - LD A,D - LD (.y_s+1),A - CPL - LD L,A - LD H,#0xFF - INC HL - LD BC,#0 - ADD HL,BC - LD A,L - LD (.l_d+1),A - LD A,H - LD (.l_d),A + LD A,B ;Store center values + LD (.x_s),A + LD A,C + LD (.y_s),A + + XOR A + LD (.x_s+1),A + LD A,D + LD (.y_s+1),A + CPL + LD L,A + LD H,#0xFF + INC HL + LD BC,#0 + ADD HL,BC + LD A,L + LD (.l_d+1),A + LD A,H + LD (.l_d),A cloop$: - LD A,(.x_s+1) - LD B,A - LD A,(.y_s+1) - SUB B - RET C - - LD A,(.style) - OR A - CALL Z,.circplot - - LD A,(.l_d) - BIT 7,A - JR Z,ycirc$ - - LD A,(.style) - OR A - CALL NZ,.horlin - LD A,(.x_s+1) - INC A - LD (.x_s+1),A - LD A,(.l_d) - LD B,A - LD A,(.l_d+1) - LD C,A - LD H,#0 - LD A,(.x_s+1) - LD L,A - ADD HL,HL - ADD HL,HL - ADD HL,BC - LD BC,#6 - ADD HL,BC - LD A,H - LD (.l_d),A - LD A,L - LD (.l_d+1),A - JR cloop$ -ycirc$: - LD A,(.style) - OR A - CALL NZ,.verlin - LD A,(.x_s+1) - INC A - LD (.x_s+1),A - LD B,#0 - LD A,(.x_s+1) - LD C,A - LD H,#0xFF - LD A,(.y_s+1) - CPL - LD L,A - INC HL - ADD HL,BC - LD A,(.l_d) - LD B,A - LD A,(.l_d+1) - LD C,A - ADD HL,HL - ADD HL,HL - ADD HL,BC - LD BC,#10 - ADD HL,BC - LD A,H - LD (.l_d),A - LD A,L - LD (.l_d+1),A - LD A,(.y_s+1) - DEC A - LD (.y_s+1),A - JP cloop$ + LD A,(.x_s+1) + LD B,A + LD A,(.y_s+1) + SUB B + RET C + + LD A,(.style) + OR A + CALL Z,.circplot + + LD A,(.l_d) + BIT 7,A + JR Z,ycirc$ + + LD A,(.style) + OR A + CALL NZ,.horlin + LD A,(.x_s+1) + INC A + LD (.x_s+1),A + LD A,(.l_d) + LD B,A + LD A,(.l_d+1) + LD C,A + LD H,#0 + LD A,(.x_s+1) + LD L,A + ADD HL,HL + ADD HL,HL + ADD HL,BC + LD BC,#6 + ADD HL,BC + LD A,H + LD (.l_d),A + LD A,L + LD (.l_d+1),A + JR cloop$ +ycirc$: + LD A,(.style) + OR A + CALL NZ,.verlin + LD A,(.x_s+1) + INC A + LD (.x_s+1),A + LD B,#0 + LD A,(.x_s+1) + LD C,A + LD H,#0xFF + LD A,(.y_s+1) + CPL + LD L,A + INC HL + ADD HL,BC + LD A,(.l_d) + LD B,A + LD A,(.l_d+1) + LD C,A + ADD HL,HL + ADD HL,HL + ADD HL,BC + LD BC,#10 + ADD HL,BC + LD A,H + LD (.l_d),A + LD A,L + LD (.l_d+1),A + LD A,(.y_s+1) + DEC A + LD (.y_s+1),A + JP cloop$ .horlin:: - LD A,(.x_s) - LD B,A - LD A,(.y_s) - LD C,A - LD A,(.x_s+1) - LD D,A - LD A,(.y_s+1) - LD E,A - PUSH BC - PUSH DE - LD A,B - SUB E - LD H,A - LD A,B - ADD E - LD B,A - LD A,C - ADD D - LD C,A - LD D,H - LD E,C - CALL .line - POP DE - POP BC - LD A,D - OR A - RET Z - PUSH BC - PUSH DE - LD A,B - SUB E - LD H,A - LD A,B - ADD E - LD B,A - LD A,C - SUB D - LD C,A - LD D,H - LD E,C - CALL .line - POP DE - POP BC - RET + LD A,(.x_s) + LD B,A + LD A,(.y_s) + LD C,A + LD A,(.x_s+1) + LD D,A + LD A,(.y_s+1) + LD E,A + PUSH BC + PUSH DE + LD A,B + SUB E + LD H,A + LD A,B + ADD E + LD B,A + LD A,C + ADD D + LD C,A + LD D,H + LD E,C + CALL .line + POP DE + POP BC + LD A,D + OR A + RET Z + PUSH BC + PUSH DE + LD A,B + SUB E + LD H,A + LD A,B + ADD E + LD B,A + LD A,C + SUB D + LD C,A + LD D,H + LD E,C + CALL .line + POP DE + POP BC + RET .verlin:: - LD A,(.x_s) - LD B,A - LD A,(.y_s) - LD C,A - LD A,(.x_s+1) - LD D,A - LD A,(.y_s+1) - LD E,A - PUSH BC - PUSH DE - LD A,B - SUB E - LD H,A - LD A,B - ADD E - LD B,A - LD A,C - ADD D - LD C,A - LD D,H - LD E,C - CALL .line - POP DE - POP BC - PUSH BC - PUSH DE - LD A,B - SUB E - LD H,A - LD A,B - ADD E - LD B,A - LD A,C - SUB D - LD C,A - LD D,H - LD E,C - CALL .line - POP DE - POP BC - LD A,D - SUB E - RET Z - PUSH BC - PUSH DE - LD A,B - SUB D - LD H,A - LD A,B - ADD D - LD B,A - LD A,C - SUB E - LD C,A - LD D,H - LD E,C - CALL .line - POP DE - POP BC - PUSH BC - PUSH DE - LD A,B - SUB D - LD H,A - LD A,B - ADD D - LD B,A - LD A,C - ADD E - LD C,A - LD D,H - LD E,C - CALL .line - POP DE - POP BC - RET + LD A,(.x_s) + LD B,A + LD A,(.y_s) + LD C,A + LD A,(.x_s+1) + LD D,A + LD A,(.y_s+1) + LD E,A + PUSH BC + PUSH DE + LD A,B + SUB E + LD H,A + LD A,B + ADD E + LD B,A + LD A,C + ADD D + LD C,A + LD D,H + LD E,C + CALL .line + POP DE + POP BC + PUSH BC + PUSH DE + LD A,B + SUB E + LD H,A + LD A,B + ADD E + LD B,A + LD A,C + SUB D + LD C,A + LD D,H + LD E,C + CALL .line + POP DE + POP BC + LD A,D + SUB E + RET Z + PUSH BC + PUSH DE + LD A,B + SUB D + LD H,A + LD A,B + ADD D + LD B,A + LD A,C + SUB E + LD C,A + LD D,H + LD E,C + CALL .line + POP DE + POP BC + PUSH BC + PUSH DE + LD A,B + SUB D + LD H,A + LD A,B + ADD D + LD B,A + LD A,C + ADD E + LD C,A + LD D,H + LD E,C + CALL .line + POP DE + POP BC + RET .circplot:: - LD A,(.x_s) - LD B,A - LD A,(.y_s) - LD C,A - LD A,(.x_s+1) - LD D,A - LD A,(.y_s+1) - LD E,A - PUSH BC - PUSH DE - LD A,B - ADD D - LD B,A - LD A,C - SUB E - LD C,A - CALL .plot - POP DE - POP BC - PUSH BC - PUSH DE - LD A,B - SUB E - LD B,A - LD A,C - SUB D - LD C,A - CALL .plot - POP DE - POP BC - PUSH BC - PUSH DE - LD A,B - SUB D - LD B,A - LD A,C - ADD E - LD C,A - CALL .plot - POP DE - POP BC - PUSH BC - PUSH DE - LD A,B - ADD E - LD B,A - LD A,C - ADD D - LD C,A - CALL .plot - POP DE - POP BC - - LD A,D - OR A - RET Z - SUB E - RET Z - - PUSH BC - PUSH DE - LD A,B - SUB D - LD B,A - LD A,C - SUB E - LD C,A - CALL .plot - POP DE - POP BC - PUSH BC - PUSH DE - LD A,B - SUB E - LD B,A - LD A,C - ADD D - LD C,A - CALL .plot - POP DE - POP BC - PUSH BC - PUSH DE - LD A,B - ADD D - LD B,A - LD A,C - ADD E - LD C,A - CALL .plot - POP DE - POP BC - PUSH BC - PUSH DE - LD A,B - ADD E - LD B,A - LD A,C - SUB D - LD C,A - CALL .plot - POP DE - POP BC - RET - - ;; Draw a box between (B,C) and (D,E) + LD A,(.x_s) + LD B,A + LD A,(.y_s) + LD C,A + LD A,(.x_s+1) + LD D,A + LD A,(.y_s+1) + LD E,A + PUSH BC + PUSH DE + LD A,B + ADD D + LD B,A + LD A,C + SUB E + LD C,A + CALL .plot + POP DE + POP BC + PUSH BC + PUSH DE + LD A,B + SUB E + LD B,A + LD A,C + SUB D + LD C,A + CALL .plot + POP DE + POP BC + PUSH BC + PUSH DE + LD A,B + SUB D + LD B,A + LD A,C + ADD E + LD C,A + CALL .plot + POP DE + POP BC + PUSH BC + PUSH DE + LD A,B + ADD E + LD B,A + LD A,C + ADD D + LD C,A + CALL .plot + POP DE + POP BC + + LD A,D + OR A + RET Z + SUB E + RET Z + + PUSH BC + PUSH DE + LD A,B + SUB D + LD B,A + LD A,C + SUB E + LD C,A + CALL .plot + POP DE + POP BC + PUSH BC + PUSH DE + LD A,B + SUB E + LD B,A + LD A,C + ADD D + LD C,A + CALL .plot + POP DE + POP BC + PUSH BC + PUSH DE + LD A,B + ADD D + LD B,A + LD A,C + ADD E + LD C,A + CALL .plot + POP DE + POP BC + PUSH BC + PUSH DE + LD A,B + ADD E + LD B,A + LD A,C + SUB D + LD C,A + CALL .plot + POP DE + POP BC + RET + + ;; Draw a box between (B,C) and (D,E) .box:: - LD A,(.x_s) - LD B,A - LD A,(.x_s+1) - LD C,A - SUB B - JR NC,ychk$ - LD A,C - LD (.x_s),A - LD A,B - LD (.x_s+1),A + LD A,(.x_s) + LD B,A + LD A,(.x_s+1) + LD C,A + SUB B + JR NC,ychk$ + LD A,C + LD (.x_s),A + LD A,B + LD (.x_s+1),A ychk$: - LD A,(.y_s) - LD B,A - LD A,(.y_s+1) - LD C,A - SUB B - JR NC,dbox$ - LD A,C - LD (.y_s),A - LD A,B - LD (.y_s+1),A + LD A,(.y_s) + LD B,A + LD A,(.y_s+1) + LD C,A + SUB B + JR NC,dbox$ + LD A,C + LD (.y_s),A + LD A,B + LD (.y_s+1),A dbox$: - LD A,(.x_s) - LD B,A - LD D,A - LD A,(.y_s) - LD C,A - LD A,(.y_s+1) - LD E,A - CALL .line - LD A,(.x_s+1) - LD B,A - LD D,A - LD A,(.y_s) - LD C,A - LD A,(.y_s+1) - LD E,A - CALL .line - LD A,(.x_s) - INC A - LD (.x_s),A - LD A,(.x_s+1) - DEC A - LD (.x_s+1),A - LD A,(.x_s) - LD B,A - LD A,(.x_s+1) - LD D,A - LD A,(.y_s) - LD C,A - LD E,A - CALL .line - LD A,(.x_s) - LD B,A - LD A,(.x_s+1) - LD D,A - LD A,(.y_s+1) - LD C,A - LD E,A - CALL .line - LD A,(.style) - OR A - RET Z - LD A,(.x_s) - LD B,A - LD A,(.x_s+1) - SUB B - RET C - LD A,(.y_s) - INC A - LD (.y_s),A - LD A,(.y_s+1) - DEC A - LD (.y_s+1),A - LD A,(.y_s) - LD B,A - LD A,(.y_s+1) - SUB B - RET C - - .if 0 - LD A,(.mod_col) ;Swap fore + back colours. - LD D,A - AND #0xF0 - LD C,A ;Preserve Style - LD A,D - AND #0x0C - RRCA - RRCA - OR C ;Foreground->background + style - LD C,A - LD A,D - AND #0x03 - RLCA - RLCA - OR C - LD (.mod_col),A - .else - LD A,(.fg_colour) - LD C,A - LD A,(.bg_colour) - LD (.fg_colour),A - LD A,C - LD (.bg_colour),A - .endif + LD A,(.x_s) + LD B,A + LD D,A + LD A,(.y_s) + LD C,A + LD A,(.y_s+1) + LD E,A + CALL .line + LD A,(.x_s+1) + LD B,A + LD D,A + LD A,(.y_s) + LD C,A + LD A,(.y_s+1) + LD E,A + CALL .line + LD A,(.x_s) + INC A + LD (.x_s),A + LD A,(.x_s+1) + DEC A + LD (.x_s+1),A + LD A,(.x_s) + LD B,A + LD A,(.x_s+1) + LD D,A + LD A,(.y_s) + LD C,A + LD E,A + CALL .line + LD A,(.x_s) + LD B,A + LD A,(.x_s+1) + LD D,A + LD A,(.y_s+1) + LD C,A + LD E,A + CALL .line + LD A,(.style) + OR A + RET Z + LD A,(.x_s) + LD B,A + LD A,(.x_s+1) + SUB B + RET C + LD A,(.y_s) + INC A + LD (.y_s),A + LD A,(.y_s+1) + DEC A + LD (.y_s+1),A + LD A,(.y_s) + LD B,A + LD A,(.y_s+1) + SUB B + RET C + + .if 0 + LD A,(.mod_col) ;Swap fore + back colours. + LD D,A + AND #0xF0 + LD C,A ;Preserve Style + LD A,D + AND #0x0C + RRCA + RRCA + OR C ;Foreground->background + style + LD C,A + LD A,D + AND #0x03 + RLCA + RLCA + OR C + LD (.mod_col),A + .else + LD A,(.fg_colour) + LD C,A + LD A,(.bg_colour) + LD (.fg_colour),A + LD A,C + LD (.bg_colour),A + .endif filllp$: - LD A,(.x_s) - LD B,A - LD A,(.x_s+1) - LD D,A - LD A,(.y_s) - LD C,A - LD E,A - CALL .line - LD A,(.y_s+1) - LD B,A - LD A,(.y_s) - CP B - JR Z,swap$ - INC A - LD (.y_s),A - JR filllp$ -swap$: - .if 0 - LD A,(.mod_col) ;Swap fore + back colours. - LD D,A - AND #0xF0 - LD C,A ;Preserve Style - LD A,D - AND #0x0C - RRCA - RRCA - OR C ;Foreground->background + style - LD C,A - LD A,D - AND #0x03 - RLCA - RLCA - OR C - LD (.mod_col),A - .else - LD A,(.fg_colour) - LD C,A - LD A,(.bg_colour) - LD (.fg_colour),A - LD A,C - LD (.bg_colour),A - .endif - RET - - ;; Draw a line between (B,C) and (D,E) + LD A,(.x_s) + LD B,A + LD A,(.x_s+1) + LD D,A + LD A,(.y_s) + LD C,A + LD E,A + CALL .line + LD A,(.y_s+1) + LD B,A + LD A,(.y_s) + CP B + JR Z,swap$ + INC A + LD (.y_s),A + JR filllp$ +swap$: + .if 0 + LD A,(.mod_col) ;Swap fore + back colours. + LD D,A + AND #0xF0 + LD C,A ;Preserve Style + LD A,D + AND #0x0C + RRCA + RRCA + OR C ;Foreground->background + style + LD C,A + LD A,D + AND #0x03 + RLCA + RLCA + OR C + LD (.mod_col),A + .else + LD A,(.fg_colour) + LD C,A + LD A,(.bg_colour) + LD (.fg_colour),A + LD A,C + LD (.bg_colour),A + .endif + RET + + ;; Draw a line between (B,C) and (D,E) .line:: - LD A,C ;Calculate Delta Y - SUB E - JR NC,s1$ - CPL - INC A + LD A,C ;Calculate Delta Y + SUB E + JR NC,s1$ + CPL + INC A -s1$: LD (.delta_y),A - LD H,A +s1$: LD (.delta_y),A + LD H,A - LD A,B ;Calculate Delta X - SUB D - JR NC,s2$ - CPL - INC A + LD A,B ;Calculate Delta X + SUB D + JR NC,s2$ + CPL + INC A -s2$: LD (.delta_x),A +s2$: LD (.delta_x),A - SUB H - JP C,y1 + SUB H + JP C,y1 - ;; Use Delta X + ;; Use Delta X - LD A,B - SUB D - JP NC,x2$ + LD A,B + SUB D + JP NC,x2$ - LD A,C - SUB E - JR Z,x3$ - LD A,#0x00 - JR NC,x3$ - LD A,#0xFF - JR x3$ + LD A,C + SUB E + JR Z,x3$ + LD A,#0x00 + JR NC,x3$ + LD A,#0xFF + JR x3$ x2$: - LD A,E - SUB C - JR Z,x2a$ - LD A,#0x00 - JR NC,x2a$ - LD A,#0xFF + LD A,E + SUB C + JR Z,x2a$ + LD A,#0x00 + JR NC,x2a$ + LD A,#0xFF x2a$: - LD B,D - LD C,E ;BC holds start X,Y + LD B,D + LD C,E ;BC holds start X,Y x3$: - LD (.l_inc),A ;Store Y increment - LD HL,#.y_table - LD D,#0x00 - LD E,C - ADD HL,DE - ADD HL,DE - LD A,(HL+) - LD H,(HL) - LD L,A - - LD A,B - AND #0xf8 - LD E,A - ADD HL,DE - ADD HL,DE - - LD A,(.delta_y) - OR A - JP Z,.xonly - - ;; Got to do it the hard way. - - ; Calculate (2*deltay) -> dinc1 - - PUSH HL - LD H,#0x00 - LD L,A - ADD HL,HL - LD A,H - LD (.dinc1),A - LD A,L - LD (.dinc1+1),A - - ; Calculate (2*deltay)-deltax -> d - - - LD D,H - LD E,L - LD A,(.delta_x) - CPL - LD L,A - LD H,#0xFF - INC HL + LD (.l_inc),A ;Store Y increment + LD HL,#.y_table + LD D,#0x00 + LD E,C + ADD HL,DE + ADD HL,DE + LD A,(HL+) + LD H,(HL) + LD L,A + + LD A,B + AND #0xf8 + LD E,A + ADD HL,DE + ADD HL,DE + + LD A,(.delta_y) + OR A + JP Z,.xonly + + ;; Got to do it the hard way. + + ; Calculate (2*deltay) -> dinc1 + + PUSH HL + LD H,#0x00 + LD L,A + ADD HL,HL + LD A,H + LD (.dinc1),A + LD A,L + LD (.dinc1+1),A + + ; Calculate (2*deltay)-deltax -> d + + + LD D,H + LD E,L + LD A,(.delta_x) + CPL + LD L,A + LD H,#0xFF + INC HL dx1$: - ADD HL,DE - LD A,H - LD (.l_d),A - LD A,L - LD (.l_d+1),A - - ; Calculate (deltay-deltax)*2 -> dinc2 - - LD A,(.delta_x) - CPL - LD L,A - LD H,#0xFF - INC HL - LD A,(.delta_y) - LD D,#0x00 - LD E,A - ADD HL,DE - ADD HL,HL - - LD A,H - LD (.dinc2),A - LD A,L - LD (.dinc2+1),A - - POP HL - - .if 0 - LD A,(.mod_col) - LD D,A - .endif - - LD A,(.delta_x) - LD E,A - - LD A,B - AND #7 - ADD #<.drawing_bits_tbl ; Table of bits is located at 0x0070 - LD C,A - LD B,#0x00 - LD A,(BC) ; Get start bit - LD B,A - LD C,A + ADD HL,DE + LD A,H + LD (.l_d),A + LD A,L + LD (.l_d+1),A + + ; Calculate (deltay-deltax)*2 -> dinc2 + + LD A,(.delta_x) + CPL + LD L,A + LD H,#0xFF + INC HL + LD A,(.delta_y) + LD D,#0x00 + LD E,A + ADD HL,DE + ADD HL,HL + + LD A,H + LD (.dinc2),A + LD A,L + LD (.dinc2+1),A + + POP HL + + .if 0 + LD A,(.mod_col) + LD D,A + .endif + + LD A,(.delta_x) + LD E,A + + LD A,B + AND #7 + ADD #<.drawing_bits_tbl ; Table of bits is located at 0x0070 + LD C,A + LD B,#0x00 + LD A,(BC) ; Get start bit + LD B,A + LD C,A xloop$: - RRC C - LD A,(.l_d) - BIT 7,A - JR Z,ychg$ - PUSH DE - BIT 7,C - JR Z,nbit$ - LD A,B - CPL - LD C,A - CALL .wrbyte - DEC HL - LD C,#0x80 - LD B,C + RRC C + LD A,(.l_d) + BIT 7,A + JR Z,ychg$ + PUSH DE + BIT 7,C + JR Z,nbit$ + LD A,B + CPL + LD C,A + CALL .wrbyte + DEC HL + LD C,#0x80 + LD B,C nbit$: - LD A,(.l_d+1) - LD D,A - LD A,(.dinc1+1) - ADD D - LD (.l_d+1),A - LD A,(.l_d) - LD D,A - LD A,(.dinc1) - ADC D - LD (.l_d),A - POP DE - JR nchg$ + LD A,(.l_d+1) + LD D,A + LD A,(.dinc1+1) + ADD D + LD (.l_d+1),A + LD A,(.l_d) + LD D,A + LD A,(.dinc1) + ADC D + LD (.l_d),A + POP DE + JR nchg$ ychg$: - PUSH DE - PUSH BC - LD A,B - CPL - LD C,A - CALL .wrbyte - LD A,(.l_inc) - OR A - JR Z,ydown$ - INC HL - LD A,L - AND #0x0F - JR NZ,bound$ - LD DE,#0x0130 - ADD HL,DE ;Correct screen address - JR bound$ + PUSH DE + PUSH BC + LD A,B + CPL + LD C,A + CALL .wrbyte + LD A,(.l_inc) + OR A + JR Z,ydown$ + INC HL + LD A,L + AND #0x0F + JR NZ,bound$ + LD DE,#0x0130 + ADD HL,DE ;Correct screen address + JR bound$ ydown$: - DEC HL - DEC HL - DEC HL - LD A,L - AND #0x0F - XOR #0x0E - JR NZ,bound$ - LD DE,#0xFED0 - ADD HL,DE ;Correct screen address + DEC HL + DEC HL + DEC HL + LD A,L + AND #0x0F + XOR #0x0E + JR NZ,bound$ + LD DE,#0xFED0 + ADD HL,DE ;Correct screen address bound$: - LD A,(.l_d+1) - LD D,A - LD A,(.dinc2+1) - ADD D - LD (.l_d+1),A - LD A,(.l_d) - LD D,A - LD A,(.dinc2) - ADC D - LD (.l_d),A - POP BC - LD B,C - POP DE + LD A,(.l_d+1) + LD D,A + LD A,(.dinc2+1) + ADD D + LD (.l_d+1),A + LD A,(.l_d) + LD D,A + LD A,(.dinc2) + ADC D + LD (.l_d),A + POP BC + LD B,C + POP DE nchg$: - BIT 7,C - JR Z,nadj$ - PUSH DE - LD DE,#0x0010 - ADD HL,DE ;Correct screen address - POP DE - LD B,C + BIT 7,C + JR Z,nadj$ + PUSH DE + LD DE,#0x0010 + ADD HL,DE ;Correct screen address + POP DE + LD B,C nadj$: - LD A,B - OR C - LD B,A - DEC E - JP NZ,xloop$ - LD A,B - CPL - LD C,A - JP .wrbyte + LD A,B + OR C + LD B,A + DEC E + JP NZ,xloop$ + LD A,B + CPL + LD C,A + JP .wrbyte .xonly:: - ;; Draw accelerated horizontal line - .if 0 - ;; xxx needed? - LD A,(.mod_col) - LD D,A - .endif - - LD A,(.delta_x) - LD E,A - INC E - - LD A,B ;check X - AND #7 ;just look at bottom 3 bits - JR Z,2$ - PUSH HL - ADD #<.drawing_bits_tbl ;Table of bits is located at 0x0070 - LD L,A - LD H,#0x00 - LD C,(HL) - POP HL - XOR A ;Clear A -1$: RRCA ;Shift data right 1 - OR C - DEC E - JR Z,3$ - BIT 0,A - JR Z,1$ - JR 3$ + ;; Draw accelerated horizontal line + .if 0 + ;; xxx needed? + LD A,(.mod_col) + LD D,A + .endif + + LD A,(.delta_x) + LD E,A + INC E + + LD A,B ;check X + AND #7 ;just look at bottom 3 bits + JR Z,2$ + PUSH HL + ADD #<.drawing_bits_tbl ;Table of bits is located at 0x0070 + LD L,A + LD H,#0x00 + LD C,(HL) + POP HL + XOR A ;Clear A +1$: RRCA ;Shift data right 1 + OR C + DEC E + JR Z,3$ + BIT 0,A + JR Z,1$ + JR 3$ 2$: - LD A,E - DEC A - AND #0xF8 - JR Z,4$ - JR 8$ + LD A,E + DEC A + AND #0xF8 + JR Z,4$ + JR 8$ 3$: - LD B,A - CPL - LD C,A - PUSH DE - CALL .wrbyte - LD DE,#0x0F - ADD HL,DE ;Correct screen address - POP DE - -8$: LD A,E - OR A - RET Z - AND #0xF8 - JR Z,4$ - - XOR A - LD C,A - CPL - LD B,A - - PUSH DE - CALL .wrbyte - LD DE,#0x0F - ADD HL,DE ;Correct screen address - POP DE - LD A,E - SUB #8 - RET Z - LD E,A - JR 8$ - -4$: LD A,#0x80 -5$: DEC E - JR Z,6$ - SRA A - JR 5$ -6$: LD B,A - CPL - LD C,A - JP .wrbyte - - ;; Use Delta Y + LD B,A + CPL + LD C,A + PUSH DE + CALL .wrbyte + LD DE,#0x0F + ADD HL,DE ;Correct screen address + POP DE + +8$: LD A,E + OR A + RET Z + AND #0xF8 + JR Z,4$ + + XOR A + LD C,A + CPL + LD B,A + + PUSH DE + CALL .wrbyte + LD DE,#0x0F + ADD HL,DE ;Correct screen address + POP DE + LD A,E + SUB #8 + RET Z + LD E,A + JR 8$ + +4$: LD A,#0x80 +5$: DEC E + JR Z,6$ + SRA A + JR 5$ +6$: LD B,A + CPL + LD C,A + JP .wrbyte + + ;; Use Delta Y y1: - LD A,C - SUB E - JP NC,y2$ - - LD A,B - SUB D - JR Z,y3$ - LD A,#0x00 - JR NC,y3$ - LD A,#0xFF - JR y3$ + LD A,C + SUB E + JP NC,y2$ + + LD A,B + SUB D + JR Z,y3$ + LD A,#0x00 + JR NC,y3$ + LD A,#0xFF + JR y3$ y2$: - LD A,C - SUB E - JR Z,y2a$ - LD A,#0x00 - -; JR NC,y2a$ ; old code; fix draw to up-left below -; LD A,#0xFF - - LD L,A ; invert delta if x1 less than x2 - LD A,B - SUB D - LD A,L - JR C,y2a$ - CPL + LD A,C + SUB E + JR Z,y2a$ + LD A,#0x00 + +; JR NC,y2a$ ; old code; fix draw to up-left below +; LD A,#0xFF + + LD L,A ; invert delta if x1 less than x2 + LD A,B + SUB D + LD A,L + JR C,y2a$ + CPL y2a$: - LD B,D - LD C,E ;BC holds start X,Y + LD B,D + LD C,E ;BC holds start X,Y y3$: - LD (.l_inc),A ;Store X increment - LD HL,#.y_table - LD D,#0x00 - LD E,C - ADD HL,DE - ADD HL,DE - LD A,(HL+) - LD H,(HL) - LD L,A - - LD A,B - AND #0xf8 - LD E,A - ADD HL,DE - ADD HL,DE - - .if 0 - ;; Trashed by later instructions - LD A,(.mod_col) - LD D,A - .endif - - LD A,(.delta_y) - LD E,A - INC E - - LD A,(.delta_x) - OR A - JP Z,.yonly - - ;; Got to do it the hard way. - - ; Calculate (2*deltax) -> dinc1 - - PUSH HL - LD H,#0x00 - LD L,A - ADD HL,HL - LD A,H - LD (.dinc1),A - LD A,L - LD (.dinc1+1),A - - ; Calculate (2*deltax)-deltay -> d - - - LD D,H - LD E,L - LD A,(.delta_y) - CPL - LD L,A - LD H,#0xFF - INC HL + LD (.l_inc),A ;Store X increment + LD HL,#.y_table + LD D,#0x00 + LD E,C + ADD HL,DE + ADD HL,DE + LD A,(HL+) + LD H,(HL) + LD L,A + + LD A,B + AND #0xf8 + LD E,A + ADD HL,DE + ADD HL,DE + + .if 0 + ;; Trashed by later instructions + LD A,(.mod_col) + LD D,A + .endif + + LD A,(.delta_y) + LD E,A + INC E + + LD A,(.delta_x) + OR A + JP Z,.yonly + + ;; Got to do it the hard way. + + ; Calculate (2*deltax) -> dinc1 + + PUSH HL + LD H,#0x00 + LD L,A + ADD HL,HL + LD A,H + LD (.dinc1),A + LD A,L + LD (.dinc1+1),A + + ; Calculate (2*deltax)-deltay -> d + + + LD D,H + LD E,L + LD A,(.delta_y) + CPL + LD L,A + LD H,#0xFF + INC HL dy1$: - ADD HL,DE - LD A,H - LD (.l_d),A - LD A,L - LD (.l_d+1),A - - ; Calculate (deltax-deltay)*2 -> dinc2 - - LD A,(.delta_y) - CPL - LD L,A - LD H,#0xFF - INC HL - LD A,(.delta_x) - LD D,#0x00 - LD E,A - ADD HL,DE - ADD HL,HL - - LD A,H - LD (.dinc2),A - LD A,L - LD (.dinc2+1),A - - POP HL - - .if 0 - ;; xxx Not used? - LD A,(.mod_col) - LD D,A - .endif - - LD A,(.delta_y) - LD E,A - - LD A,B - AND #7 - ADD #<.drawing_bits_tbl ; Table of bits is located at 0x0070 - LD C,A - LD B,#0x00 - LD A,(BC) ; Get start bit - LD B,A - LD C,A + ADD HL,DE + LD A,H + LD (.l_d),A + LD A,L + LD (.l_d+1),A + + ; Calculate (deltax-deltay)*2 -> dinc2 + + LD A,(.delta_y) + CPL + LD L,A + LD H,#0xFF + INC HL + LD A,(.delta_x) + LD D,#0x00 + LD E,A + ADD HL,DE + ADD HL,HL + + LD A,H + LD (.dinc2),A + LD A,L + LD (.dinc2+1),A + + POP HL + + .if 0 + ;; xxx Not used? + LD A,(.mod_col) + LD D,A + .endif + + LD A,(.delta_y) + LD E,A + + LD A,B + AND #7 + ADD #<.drawing_bits_tbl ; Table of bits is located at 0x0070 + LD C,A + LD B,#0x00 + LD A,(BC) ; Get start bit + LD B,A + LD C,A yloop$: - PUSH DE - PUSH BC - LD A,B - CPL - LD C,A - CALL .wrbyte - INC HL - LD A,L - AND #0x0F - JR NZ,nybound$ - LD DE,#0x0130 - ADD HL,DE ;Correct screen address + PUSH DE + PUSH BC + LD A,B + CPL + LD C,A + CALL .wrbyte + INC HL + LD A,L + AND #0x0F + JR NZ,nybound$ + LD DE,#0x0130 + ADD HL,DE ;Correct screen address nybound$: - POP BC - LD A,(.l_d) - BIT 7,A - JR Z,xchg$ - LD A,(.l_d+1) - LD D,A - LD A,(.dinc1+1) - ADD D - LD (.l_d+1),A - LD A,(.l_d) - LD D,A - LD A,(.dinc1) - ADC D - LD (.l_d),A - JR nchgy$ + POP BC + LD A,(.l_d) + BIT 7,A + JR Z,xchg$ + LD A,(.l_d+1) + LD D,A + LD A,(.dinc1+1) + ADD D + LD (.l_d+1),A + LD A,(.l_d) + LD D,A + LD A,(.dinc1) + ADC D + LD (.l_d),A + JR nchgy$ xchg$: - LD A,(.l_inc) - OR A - JR NZ,yright$ - RLC B - BIT 0,B - JR Z,boundy$ - LD DE,#0xFFF0 - ADD HL,DE ;Correct screen address - JR boundy$ + LD A,(.l_inc) + OR A + JR NZ,yright$ + RLC B + BIT 0,B + JR Z,boundy$ + LD DE,#0xFFF0 + ADD HL,DE ;Correct screen address + JR boundy$ yright$: - RRC B - BIT 7,B - JR Z,boundy$ - LD DE,#0x0010 - ADD HL,DE ;Correct screen address + RRC B + BIT 7,B + JR Z,boundy$ + LD DE,#0x0010 + ADD HL,DE ;Correct screen address boundy$: - LD A,(.l_d+1) - LD D,A - LD A,(.dinc2+1) - ADD D - LD (.l_d+1),A - LD A,(.l_d) - LD D,A - LD A,(.dinc2) - ADC D - LD (.l_d),A + LD A,(.l_d+1) + LD D,A + LD A,(.dinc2+1) + ADD D + LD (.l_d+1),A + LD A,(.l_d) + LD D,A + LD A,(.dinc2) + ADC D + LD (.l_d),A nchgy$: - POP DE - DEC E - JR NZ,yloop$ - LD A,B - CPL - LD C,A - JP .wrbyte + POP DE + DEC E + JR NZ,yloop$ + LD A,B + CPL + LD C,A + JP .wrbyte .yonly:: - ;; Draw accelerated vertical line - LD A,B ;check X - AND #7 ;just look at bottom 3 bits - PUSH HL - ADD #<.drawing_bits_tbl ;Table of bits is located at 0x0070 - LD L,A - LD H,#0x00 - LD A,(HL) ;Get mask bit - POP HL - LD B,A - CPL - LD C,A - -1$: PUSH DE - CALL .wrbyte - INC HL ;Correct screen address - LD A,L - AND #0x0F - JR NZ,2$ - LD DE,#0x0130 - ADD HL,DE -2$: POP DE - DEC E - RET Z - JR 1$ - - ;; Draw a point at (B,C) with mode and color D + ;; Draw accelerated vertical line + LD A,B ;check X + AND #7 ;just look at bottom 3 bits + PUSH HL + ADD #<.drawing_bits_tbl ;Table of bits is located at 0x0070 + LD L,A + LD H,#0x00 + LD A,(HL) ;Get mask bit + POP HL + LD B,A + CPL + LD C,A + +1$: PUSH DE + CALL .wrbyte + INC HL ;Correct screen address + LD A,L + AND #0x0F + JR NZ,2$ + LD DE,#0x0130 + ADD HL,DE +2$: POP DE + DEC E + RET Z + JR 1$ + + ;; Draw a point at (B,C) with mode and color D .plot:: - LD HL,#.y_table - LD D,#0x00 - LD E,C - ADD HL,DE - ADD HL,DE - LD A,(HL+) - LD H,(HL) - LD L,A - - LD A,B - AND #0xf8 - LD E,A - ADD HL,DE - ADD HL,DE - - LD A,B - - AND #7 - ADD #<.drawing_bits_tbl ; Table of bits is located at 0x0070 - LD C,A - LD B,#0x00 - LD A,(BC) - LD B,A - CPL - LD C,A + LD HL,#.y_table + LD D,#0x00 + LD E,C + ADD HL,DE + ADD HL,DE + LD A,(HL+) + LD H,(HL) + LD L,A + + LD A,B + AND #0xf8 + LD E,A + ADD HL,DE + ADD HL,DE + + LD A,B + + AND #7 + ADD #<.drawing_bits_tbl ; Table of bits is located at 0x0070 + LD C,A + LD B,#0x00 + LD A,(BC) + LD B,A + CPL + LD C,A .wrbyte:: - .if 0 - LD A,(.mod_col) ; Restore color and mode - LD D,A - - BIT 5,D - JR NZ,10$ - BIT 6,D - JR NZ,20$ - BIT 7,D - JR NZ,30$ - .else - LD A,(.fg_colour) - LD D,A - LD A,(.draw_mode) - CP #.M_OR - JR Z,10$ - CP #.M_XOR - JR Z,20$ - CP #.M_AND - JR Z,30$ - .endif - - ; Fall through to SOLID by default + .if 0 + LD A,(.mod_col) ; Restore color and mode + LD D,A + + BIT 5,D + JR NZ,10$ + BIT 6,D + JR NZ,20$ + BIT 7,D + JR NZ,30$ + .else + LD A,(.fg_colour) + LD D,A + LD A,(.draw_mode) + CP #.M_OR + JR Z,10$ + CP #.M_XOR + JR Z,20$ + CP #.M_AND + JR Z,30$ + .endif + + ; Fall through to SOLID by default 1$: - ;; Solid - LD E,B - .if 0 - BIT 2,D - .else - BIT 0,D - .endif - JR NZ,2$ - PUSH BC - LD B,#0x00 + ;; Solid + LD E,B + .if 0 + BIT 2,D + .else + BIT 0,D + .endif + JR NZ,2$ + PUSH BC + LD B,#0x00 2$: - .if 0 - BIT 3,D - .else - BIT 1,D - .endif - JR NZ,3$ - LD E,#0x00 + .if 0 + BIT 3,D + .else + BIT 1,D + .endif + JR NZ,3$ + LD E,#0x00 3$: - WAIT_STAT - - LD A,(HL) - AND C - OR B - LD (HL+),A - - LD A,(HL) - AND C - OR E - LD (HL),A - LD A,B - OR A - RET NZ - POP BC - RET + WAIT_STAT + + LD A,(HL) + AND C + OR B + LD (HL+),A + + LD A,(HL) + AND C + OR E + LD (HL),A + LD A,B + OR A + RET NZ + POP BC + RET 10$: - ;; Or - LD C,B - .if 0 - BIT 2,D - .else - BIT 0,D - .endif - JR NZ,11$ - LD B,#0x00 + ;; Or + LD C,B + .if 0 + BIT 2,D + .else + BIT 0,D + .endif + JR NZ,11$ + LD B,#0x00 11$: - .if 0 - BIT 3,D - .else - BIT 1,D - .endif - JR NZ,12$ - LD C,#0x00 + .if 0 + BIT 3,D + .else + BIT 1,D + .endif + JR NZ,12$ + LD C,#0x00 12$: - WAIT_STAT + WAIT_STAT - LD A,(HL) - OR B - LD (HL+),A + LD A,(HL) + OR B + LD (HL+),A - LD A,(HL) - OR C - LD (HL),A - RET + LD A,(HL) + OR C + LD (HL),A + RET 20$: - ;; Xor - LD C,B - .if 0 - BIT 2,D - .else - BIT 0,D - .endif - JR NZ,21$ - LD B,#0x00 + ;; Xor + LD C,B + .if 0 + BIT 2,D + .else + BIT 0,D + .endif + JR NZ,21$ + LD B,#0x00 21$: - .if 0 - BIT 3,D - .else - BIT 1,D - .endif - JR NZ,22$ - LD C,#0x00 + .if 0 + BIT 3,D + .else + BIT 1,D + .endif + JR NZ,22$ + LD C,#0x00 22$: - WAIT_STAT + WAIT_STAT - LD A,(HL) - XOR B - LD (HL+),A + LD A,(HL) + XOR B + LD (HL+),A - LD A,(HL) - XOR C - LD (HL),A - RET + LD A,(HL) + XOR C + LD (HL),A + RET 30$: - ;; And - LD B,C - .if 0 - BIT 2,D - .else - BIT 0,D - .endif - JR Z,31$ - LD B,#0xFF + ;; And + LD B,C + .if 0 + BIT 2,D + .else + BIT 0,D + .endif + JR Z,31$ + LD B,#0xFF 31$: - .if 0 - BIT 3,D - .else - BIT 1,D - .endif - JR Z,32$ - LD C,#0xFF + .if 0 + BIT 3,D + .else + BIT 1,D + .endif + JR Z,32$ + LD C,#0xFF 32$: - WAIT_STAT + WAIT_STAT - LD A,(HL) - AND B - LD (HL+),A + LD A,(HL) + AND B + LD (HL+),A - LD A,(HL) - AND C - LD (HL),A - RET + LD A,(HL) + AND C + LD (HL),A + RET - ;; Get color of pixel at point (B,C) returns in A + ;; Get color of pixel at point (B,C) returns in A .getpix:: - LD HL,#.y_table - LD D,#0x00 - LD E,C - ADD HL,DE - ADD HL,DE - LD A,(HL+) - LD H,(HL) - LD L,A - - LD A,B - AND #0xf8 - LD E,A - ADD HL,DE - ADD HL,DE - - LD A,B - - AND #7 - ADD #<.drawing_bits_tbl ; Table of bits is located at 0x0070 - LD C,A - LD B,#0x00 - LD A,(BC) - LD C,A - - WAIT_STAT - - LD A,(HL+) - LD D,A - LD A,(HL+) - LD E,A - LD B,#0 - LD A,D - AND C - JR Z,1$ - SET 0,B -1$: LD A,E - AND C - JR Z,2$ - SET 1,B -2$: LD E,B - RET - - ;; Write character C + LD HL,#.y_table + LD D,#0x00 + LD E,C + ADD HL,DE + ADD HL,DE + LD A,(HL+) + LD H,(HL) + LD L,A + + LD A,B + AND #0xf8 + LD E,A + ADD HL,DE + ADD HL,DE + + LD A,B + + AND #7 + ADD #<.drawing_bits_tbl ; Table of bits is located at 0x0070 + LD C,A + LD B,#0x00 + LD A,(BC) + LD C,A + + WAIT_STAT + + LD A,(HL+) + LD D,A + LD A,(HL+) + LD E,A + LD B,#0 + LD A,D + AND C + JR Z,1$ + SET 0,B +1$: LD A,E + AND C + JR Z,2$ + SET 1,B +2$: LD E,B + RET + + ;; Write character C .wrtchr:: - LD HL,#.y_table - LD D,#0x00 - LD A,(.ty) - RLCA - RLCA - RLCA - LD E,A - ADD HL,DE - ADD HL,DE - LD A,(HL+) - LD B, A - LD H,(HL) - LD L,B - - LD A,(.tx) - RLCA - RLCA - RLCA - LD E,A - ADD HL,DE - ADD HL,DE - - LD A,C - LD B,H - LD C,L - - LD H,D - LD L,A - ADD HL,HL - ADD HL,HL - ADD HL,HL - - .if 0 - LD DE,#.tp1 - .else - .globl _font_ibm_fixed_tiles - - LD DE,#_font_ibm_fixed_tiles - .endif - - ADD HL,DE - - LD D,H - LD E,L - LD H,B - LD L,C - - .if 0 - LD A,(.mod_col) - LD C,A - .else - LD A,(.fg_colour) - LD C,A - .endif + LD HL,#.y_table + LD D,#0x00 + LD A,(.ty) + RLCA + RLCA + RLCA + LD E,A + ADD HL,DE + ADD HL,DE + LD A,(HL+) + LD B, A + LD H,(HL) + LD L,B + + LD A,(.tx) + RLCA + RLCA + RLCA + LD E,A + ADD HL,DE + ADD HL,DE + + LD A,C + LD B,H + LD C,L + + LD H,D + LD L,A + ADD HL,HL + ADD HL,HL + ADD HL,HL + + .if 0 + LD DE,#.tp1 + .else + .globl _font_ibm_fixed_tiles + + LD DE,#_font_ibm_fixed_tiles + .endif + + ADD HL,DE + + LD D,H + LD E,L + LD H,B + LD L,C + + .if 0 + LD A,(.mod_col) + LD C,A + .else + LD A,(.fg_colour) + LD C,A + .endif 1$: - LD A,(DE) - INC DE - PUSH DE - - .if 1 - PUSH HL - LD HL,#.bg_colour - LD L,(HL) - .endif - - LD B,A - XOR A - .if 0 - BIT 0,C - .else - BIT 0,L - .endif - JR Z,2$ - CPL -2$: OR B - .if 0 - BIT 2,C - .else - BIT 0,C - .endif - JR NZ,3$ - XOR B -3$: LD D,A - XOR A - .if 0 - BIT 1,C - .else - BIT 1,L - .endif - JR Z,4$ - CPL -4$: OR B - .if 0 - BIT 3,C - .else - BIT 1,C - .endif - JR NZ,5$ - XOR B -5$: - LD E,A - .if 1 - POP HL - .endif - - WAIT_STAT - - LD A,D - LD (HL+),A - LD A,E - LD (HL+),A - POP DE - LD A,L - AND #0x0F - JR NZ,1$ - RET - - .area _CODE -_gotogxy:: ; Banked - LDA HL,.BANKOV(SP) ; Skip return address - LD A,(HL+) ; A = x - LD (.tx),A - LD A,(HL+) ; A = y - LD (.ty),A - - RET - -_wrtchr:: ; Banked - PUSH BC - - LD A,(.mode) - CP #.G_MODE - CALL NZ,.gmode - - LDA HL,.BANKOV+2(SP) ; Skip return address and registers - LD A,(HL) - LD C,A ; C = Char to print - - CALL .wrtchr - CALL .adv_gcurs - - POP BC - RET - -_getpix:: ; Banked - PUSH BC - - LDA HL,.BANKOV+2(SP) ; Skip return address and registers - LD A,(HL+) ; B = x - LD B,A - LD A,(HL+) ; C = y - LD C,A - - CALL .getpix - - POP BC - RET - -_circle:: ; Banked - PUSH BC - - LD A,(.mode) - CP #.G_MODE - CALL NZ,.gmode - - LDA HL,.BANKOV+2(SP) ; Skip return address and registers - LD A,(HL+) ; B = x - LD B,A - LD A,(HL+) ; C = y - LD C,A - LD A,(HL+) ; D = Radius - LD D,A - LD A,(HL) - LD (.style),A - - CALL .circle - - POP BC - RET - -_box:: ; Banked - PUSH BC - - LD A,(.mode) - CP #.G_MODE - CALL NZ,.gmode - - LDA HL,.BANKOV+2(SP) ; Skip return address and registers - LD A,(HL+) ; B = x1 - LD (.x_s),A - LD A,(HL+) ; C = y1 - LD (.y_s),A - LD A,(HL+) ; D = x2 - LD (.x_s+1),A - LD A,(HL+) ; E = y2 - LD (.y_s+1),A - LD A,(HL) - LD (.style),A - CALL .box - POP BC - RET - -_line:: ; Banked - PUSH BC - - LD A,(.mode) - CP #.G_MODE - CALL NZ,.gmode - - LDA HL,.BANKOV+2(SP) ; Skip return address and registers - LD A,(HL+) ; B = x1 - LD B,A - LD A,(HL+) ; C = y1 - LD C,A - LD A,(HL+) ; D = x2 - LD D,A - LD A,(HL+) ; E = y2 - LD E,A - - CALL .line - - POP BC - RET - -_plot_point:: ; Banked - PUSH BC - - LD A,(.mode) - CP #.G_MODE - CALL NZ,.gmode - - LDA HL,.BANKOV+2(SP) ; Skip return address and registers - LD A,(HL+) ; B = x - LD B,A - LD A,(HL+) ; C = y - LD C,A - - CALL .plot - - POP BC - RET - - ;; Old, compatible version of plot() -_plot:: ; Banked - PUSH BC - - LD A,(.mode) - CP #.G_MODE - CALL NZ,.gmode - - LDA HL,.BANKOV+2(SP) ; Skip return address and registers - LD A,(HL+) ; B = x - LD B,A - LD A,(HL+) ; C = y - LD C,A - LD A,(HL+) ; colour - LD (.fg_colour),A - LD A,(HL+) ; mode - LD (.draw_mode),A - - CALL .plot - - POP BC - RET - - .area _BASE -_switch_data:: ; Non Banked as pointer - PUSH BC - - LD A,(.mode) - CP #.G_MODE - CALL NZ,.gmode - - LDA HL,4(SP) ; Skip return address and registers - LD A,(HL+) ; B = x - LD B,A - LD A,(HL+) ; C = y - LD C,A - LD A,(HL+) ; DE = src - LD E,A - LD A,(HL+) - LD D,A - LD A,(HL+) ; HL = dst - LD H,(HL) - LD L,A - - CALL .switch_data - - POP BC - RET - - -_draw_image:: ; Non banked as pointer - PUSH BC - - LD A,(.mode) - CP #.G_MODE - CALL NZ,.gmode - - LDA HL,4(SP) ; Skip return address and registers - LD A,(HL+) ; HL = data - LD C,A - LD B,(HL) - - CALL .draw_image - - POP BC - RET - - .area _BASE + LD A,(DE) + INC DE + PUSH DE + + .if 1 + PUSH HL + LD HL,#.bg_colour + LD L,(HL) + .endif + + LD B,A + XOR A + .if 0 + BIT 0,C + .else + BIT 0,L + .endif + JR Z,2$ + CPL +2$: OR B + .if 0 + BIT 2,C + .else + BIT 0,C + .endif + JR NZ,3$ + XOR B +3$: LD D,A + XOR A + .if 0 + BIT 1,C + .else + BIT 1,L + .endif + JR Z,4$ + CPL +4$: OR B + .if 0 + BIT 3,C + .else + BIT 1,C + .endif + JR NZ,5$ + XOR B +5$: + LD E,A + .if 1 + POP HL + .endif + + WAIT_STAT + + LD A,D + LD (HL+),A + LD A,E + LD (HL+),A + POP DE + LD A,L + AND #0x0F + JR NZ,1$ + RET + + .area _CODE +_gotogxy:: ; Banked + LDA HL,.BANKOV(SP) ; Skip return address + LD A,(HL+) ; A = x + LD (.tx),A + LD A,(HL+) ; A = y + LD (.ty),A + + RET + +_wrtchr:: ; Banked + PUSH BC + + LD A,(.mode) + CP #.G_MODE + CALL NZ,.gmode + + LDA HL,.BANKOV+2(SP) ; Skip return address and registers + LD A,(HL) + LD C,A ; C = Char to print + + CALL .wrtchr + CALL .adv_gcurs + + POP BC + RET + +_getpix:: ; Banked + PUSH BC + + LDA HL,.BANKOV+2(SP) ; Skip return address and registers + LD A,(HL+) ; B = x + LD B,A + LD A,(HL+) ; C = y + LD C,A + + CALL .getpix + + POP BC + RET + +_circle:: ; Banked + PUSH BC + + LD A,(.mode) + CP #.G_MODE + CALL NZ,.gmode + + LDA HL,.BANKOV+2(SP) ; Skip return address and registers + LD A,(HL+) ; B = x + LD B,A + LD A,(HL+) ; C = y + LD C,A + LD A,(HL+) ; D = Radius + LD D,A + LD A,(HL) + LD (.style),A + + CALL .circle + + POP BC + RET + +_box:: ; Banked + PUSH BC + + LD A,(.mode) + CP #.G_MODE + CALL NZ,.gmode + + LDA HL,.BANKOV+2(SP) ; Skip return address and registers + LD A,(HL+) ; B = x1 + LD (.x_s),A + LD A,(HL+) ; C = y1 + LD (.y_s),A + LD A,(HL+) ; D = x2 + LD (.x_s+1),A + LD A,(HL+) ; E = y2 + LD (.y_s+1),A + LD A,(HL) + LD (.style),A + CALL .box + POP BC + RET + +_line:: ; Banked + PUSH BC + + LD A,(.mode) + CP #.G_MODE + CALL NZ,.gmode + + LDA HL,.BANKOV+2(SP) ; Skip return address and registers + LD A,(HL+) ; B = x1 + LD B,A + LD A,(HL+) ; C = y1 + LD C,A + LD A,(HL+) ; D = x2 + LD D,A + LD A,(HL+) ; E = y2 + LD E,A + + CALL .line + + POP BC + RET + +_plot_point:: ; Banked + PUSH BC + + LD A,(.mode) + CP #.G_MODE + CALL NZ,.gmode + + LDA HL,.BANKOV+2(SP) ; Skip return address and registers + LD A,(HL+) ; B = x + LD B,A + LD A,(HL+) ; C = y + LD C,A + + CALL .plot + + POP BC + RET + + ;; Old, compatible version of plot() +_plot:: ; Banked + PUSH BC + + LD A,(.mode) + CP #.G_MODE + CALL NZ,.gmode + + LDA HL,.BANKOV+2(SP) ; Skip return address and registers + LD A,(HL+) ; B = x + LD B,A + LD A,(HL+) ; C = y + LD C,A + LD A,(HL+) ; colour + LD (.fg_colour),A + LD A,(HL+) ; mode + LD (.draw_mode),A + + CALL .plot + + POP BC + RET + + .area _BASE +_switch_data:: ; Non Banked as pointer + PUSH BC + + LD A,(.mode) + CP #.G_MODE + CALL NZ,.gmode + + LDA HL,4(SP) ; Skip return address and registers + LD A,(HL+) ; B = x + LD B,A + LD A,(HL+) ; C = y + LD C,A + LD A,(HL+) ; DE = src + LD E,A + LD A,(HL+) + LD D,A + LD A,(HL+) ; HL = dst + LD H,(HL) + LD L,A + + CALL .switch_data + + POP BC + RET + + +_draw_image:: ; Non banked as pointer + PUSH BC + + LD A,(.mode) + CP #.G_MODE + CALL NZ,.gmode + + LDA HL,4(SP) ; Skip return address and registers + LD A,(HL+) ; HL = data + LD C,A + LD B,(HL) + + CALL .draw_image + + POP BC + RET + + .area _BASE .y_table:: - .word 0x8100,0x8102,0x8104,0x8106,0x8108,0x810A,0x810C,0x810E - .word 0x8240,0x8242,0x8244,0x8246,0x8248,0x824A,0x824C,0x824E - .word 0x8380,0x8382,0x8384,0x8386,0x8388,0x838A,0x838C,0x838E - .word 0x84C0,0x84C2,0x84C4,0x84C6,0x84C8,0x84CA,0x84CC,0x84CE - .word 0x8600,0x8602,0x8604,0x8606,0x8608,0x860A,0x860C,0x860E - .word 0x8740,0x8742,0x8744,0x8746,0x8748,0x874A,0x874C,0x874E - .word 0x8880,0x8882,0x8884,0x8886,0x8888,0x888A,0x888C,0x888E - .word 0x89C0,0x89C2,0x89C4,0x89C6,0x89C8,0x89CA,0x89CC,0x89CE - .word 0x8B00,0x8B02,0x8B04,0x8B06,0x8B08,0x8B0A,0x8B0C,0x8B0E - .word 0x8C40,0x8C42,0x8C44,0x8C46,0x8C48,0x8C4A,0x8C4C,0x8C4E - .word 0x8D80,0x8D82,0x8D84,0x8D86,0x8D88,0x8D8A,0x8D8C,0x8D8E - .word 0x8EC0,0x8EC2,0x8EC4,0x8EC6,0x8EC8,0x8ECA,0x8ECC,0x8ECE - .word 0x9000,0x9002,0x9004,0x9006,0x9008,0x900A,0x900C,0x900E - .word 0x9140,0x9142,0x9144,0x9146,0x9148,0x914A,0x914C,0x914E - .word 0x9280,0x9282,0x9284,0x9286,0x9288,0x928A,0x928C,0x928E - .word 0x93C0,0x93C2,0x93C4,0x93C6,0x93C8,0x93CA,0x93CC,0x93CE - .word 0x9500,0x9502,0x9504,0x9506,0x9508,0x950A,0x950C,0x950E - .word 0x9640,0x9642,0x9644,0x9646,0x9648,0x964A,0x964C,0x964E + .word 0x8100,0x8102,0x8104,0x8106,0x8108,0x810A,0x810C,0x810E + .word 0x8240,0x8242,0x8244,0x8246,0x8248,0x824A,0x824C,0x824E + .word 0x8380,0x8382,0x8384,0x8386,0x8388,0x838A,0x838C,0x838E + .word 0x84C0,0x84C2,0x84C4,0x84C6,0x84C8,0x84CA,0x84CC,0x84CE + .word 0x8600,0x8602,0x8604,0x8606,0x8608,0x860A,0x860C,0x860E + .word 0x8740,0x8742,0x8744,0x8746,0x8748,0x874A,0x874C,0x874E + .word 0x8880,0x8882,0x8884,0x8886,0x8888,0x888A,0x888C,0x888E + .word 0x89C0,0x89C2,0x89C4,0x89C6,0x89C8,0x89CA,0x89CC,0x89CE + .word 0x8B00,0x8B02,0x8B04,0x8B06,0x8B08,0x8B0A,0x8B0C,0x8B0E + .word 0x8C40,0x8C42,0x8C44,0x8C46,0x8C48,0x8C4A,0x8C4C,0x8C4E + .word 0x8D80,0x8D82,0x8D84,0x8D86,0x8D88,0x8D8A,0x8D8C,0x8D8E + .word 0x8EC0,0x8EC2,0x8EC4,0x8EC6,0x8EC8,0x8ECA,0x8ECC,0x8ECE + .word 0x9000,0x9002,0x9004,0x9006,0x9008,0x900A,0x900C,0x900E + .word 0x9140,0x9142,0x9144,0x9146,0x9148,0x914A,0x914C,0x914E + .word 0x9280,0x9282,0x9284,0x9286,0x9288,0x928A,0x928C,0x928E + .word 0x93C0,0x93C2,0x93C4,0x93C6,0x93C8,0x93CA,0x93CC,0x93CE + .word 0x9500,0x9502,0x9504,0x9506,0x9508,0x950A,0x950C,0x950E + .word 0x9640,0x9642,0x9644,0x9646,0x9648,0x964A,0x964C,0x964E diff --git a/gbdk-lib/libc/gb/drawing_isr.s b/gbdk-lib/libc/gb/drawing_isr.s @@ -4,7 +4,7 @@ .drawing_vbl:: LDH A,(.LCDC) - OR #0b00010000 ; Set BG Chr to 0x8000 + OR #LCDCF_BG8000 ; Set BG Chr to 0x8000 LDH (.LCDC),A LD A,#72 ; Set line at which LCD interrupt occurs @@ -17,7 +17,7 @@ WAIT_STAT LDH A,(.LCDC) - AND #0b11101111 ; Set BG Chr to 0x8800 + AND #~LCDCF_BG8000 ; Set BG Chr to 0x8800 LDH (.LCDC),A RET diff --git a/gbdk-lib/libc/gb/fill_rect.s b/gbdk-lib/libc/gb/fill_rect.s @@ -1,85 +1,85 @@ - .include "global.s" + .include "global.s" - .area _BASE + .area _BASE .fill_rect_wtt:: - PUSH HL - LDH A,(.LCDC) - BIT 6,A - JR Z,.is98 - JR .is9c - ;; Initialize background tile table with B + PUSH HL + LDH A,(.LCDC) + AND #LCDCF_WIN9C00 + JR Z,.is98 + JR .is9c + ;; Initialize background tile table with B .fill_rect_btt:: - PUSH HL - LDH A,(.LCDC) - BIT 3,A - JR NZ,.is9c + PUSH HL + LDH A,(.LCDC) + AND #LCDCF_BG9C00 + JR NZ,.is9c .is98: - LD HL,#0x9800 ; HL = origin - JR .fill_rect + LD HL,#0x9800 ; HL = origin + JR .fill_rect .is9c: - LD HL,#0x9C00 ; HL = origin + LD HL,#0x9C00 ; HL = origin - ;; fills rectangle area with tile B at XY = DE, size WH on stack, to vram from address (HL) + ;; fills rectangle area with tile B at XY = DE, size WH on stack, to vram from address (HL) .fill_rect: - PUSH BC ; Store source + PUSH BC ; Store source - SWAP E - RLC E - LD A,E - AND #0x03 - ADD H - LD B,A - LD A,#0xE0 - AND E - ADD D - LD C,A ; dest BC = HL + 0x20 * Y + X + SWAP E + RLC E + LD A,E + AND #0x03 + ADD H + LD B,A + LD A,#0xE0 + AND E + ADD D + LD C,A ; dest BC = HL + 0x20 * Y + X - POP HL ; H = Tile - POP DE ; DE = WH - PUSH DE ; store WH - PUSH BC ; store dest + POP HL ; H = Tile + POP DE ; DE = WH + PUSH DE ; store WH + PUSH BC ; store dest -3$: ; Copy W tiles +3$: ; Copy W tiles - WAIT_STAT - LD A, H - LD (BC), A - - LD A, C ; inc dest and wrap around - AND #0xE0 - LD E, A - LD A, C - INC A - AND #0x1F - OR E - LD C, A + WAIT_STAT + LD A, H + LD (BC), A + + LD A, C ; inc dest and wrap around + AND #0xE0 + LD E, A + LD A, C + INC A + AND #0x1F + OR E + LD C, A - DEC D - JR NZ, 3$ + DEC D + JR NZ, 3$ - POP BC - POP DE + POP BC + POP DE - DEC E - RET Z + DEC E + RET Z - PUSH DE + PUSH DE - LD A, B ; next row and wrap around - AND #0xFC - LD E, A ; save high bits + LD A, B ; next row and wrap around + AND #0xFC + LD E, A ; save high bits - LD A,#0x20 + LD A,#0x20 - ADD C - LD C, A - ADC B - SUB C - AND #0x03 - OR E ; restore high bits - LD B, A + ADD C + LD C, A + ADC B + SUB C + AND #0x03 + OR E ; restore high bits + LD B, A - PUSH BC - - JR 3$ + PUSH BC + + JR 3$ diff --git a/gbdk-lib/libc/gb/font.s b/gbdk-lib/libc/gb/font.s @@ -1,709 +1,705 @@ ; font.ms ; -; Michael Hope, 1999 -; michaelh@earthling.net -; Distrubuted under the Artistic License - see www.opensource.org +; Michael Hope, 1999 +; michaelh@earthling.net +; Distrubuted under the Artistic License - see www.opensource.org ; - .include "global.s" + .include "global.s" - .globl .cr_curs - .globl .adv_curs - .globl .cury, .curx - .globl .display_off + .globl .cr_curs + .globl .adv_curs + .globl .cury, .curx + .globl .display_off - ; Structure offsets - sfont_handle_sizeof = 3 - sfont_handle_font = 1 - sfont_handle_first_tile = 0 + ; Structure offsets + sfont_handle_sizeof = 3 + sfont_handle_font = 1 + sfont_handle_first_tile = 0 - ; Encoding types - lower 2 bits of font - FONT_256ENCODING = 0 - FONT_128ENCODING = 1 - FONT_NOENCODING = 2 + ; Encoding types - lower 2 bits of font + FONT_256ENCODING = 0 + FONT_128ENCODING = 1 + FONT_NOENCODING = 2 - ; Other bits - FONT_BCOMPRESSED = 2 - - .CR = 0x0A ; Unix - .SPACE = 0x00 + ; Other bits + FONT_BCOMPRESSED = 2 + + .CR = 0x0A ; Unix + .SPACE = 0x00 - ; Maximum number of fonts - .MAX_FONTS = 6 + ; Maximum number of fonts + .MAX_FONTS = 6 - .area _FONT_HEADER (ABS) + .area _FONT_HEADER (ABS) - .org .MODE_TABLE+4*.T_MODE - JP .tmode + .org .MODE_TABLE+4*.T_MODE + JP .tmode - .module font.ms + .module font.ms - ; Globals from drawing.s - ; FIXME: Hmmm... check the linkage of these - .globl .fg_colour - .globl .bg_colour + ; Globals from drawing.s + ; FIXME: Hmmm... check the linkage of these + .globl .fg_colour + .globl .bg_colour - .area _BSS - ; The current font + .area _BSS + ; The current font .start_font_vars: font_current:: - .ds sfont_handle_sizeof - ; Cached copy of the first free tile + .ds sfont_handle_sizeof + ; Cached copy of the first free tile font_first_free_tile:: - .ds 1 - ; Table containing descriptors for all of the fonts + .ds 1 + ; Table containing descriptors for all of the fonts font_table:: - .ds sfont_handle_sizeof*.MAX_FONTS + .ds sfont_handle_sizeof*.MAX_FONTS .end_font_vars: - .area _GSINIT + .area _GSINIT - xor a - ld (#.curx),a - ld (#.cury),a - ld hl,#.start_font_vars - ld c,#(.end_font_vars - .start_font_vars) - rst 0x28 + xor a + ld (#.curx),a + ld (#.cury),a + ld hl,#.start_font_vars + ld c,#(.end_font_vars - .start_font_vars) + rst 0x28 - .area _BASE + .area _BASE -_font_load_ibm:: ; Banked - ld hl,#_font_ibm - call font_load - ret - - ; Copy uncompressed 16 byte tiles from (BC) to (HL), length = DE*2 - ; Note: HL must be aligned on a uint16_t boundry +_font_load_ibm:: ; Banked + ld hl,#_font_ibm + call font_load + ret + + ; Copy uncompressed 16 byte tiles from (BC) to (HL), length = DE*2 + ; Note: HL must be aligned on a uint16_t boundry font_copy_uncompressed:: - ld a,d - or e - ret z - - ld a,h - cp #0x98 - jr c,4$ - sub #0x98-0x88 - ld h,a + ld a,d + or e + ret z + + ld a,h + cp #0x98 + jr c,4$ + sub #0x98-0x88 + ld h,a 4$: - xor a - cp e ; Special for when e=0 you will get another loop - jr nz,1$ - dec d + xor a + cp e ; Special for when e=0 you will get another loop + jr nz,1$ + dec d 1$: - WAIT_STAT - ld a,(bc) - ld (hl+),a - inc bc - - WAIT_STAT - ld a,(bc) - ld (hl),a - inc bc - - inc l - jr nz,2$ - inc h - ld a,h ; Special wrap-around - cp #0x98 - jr nz,2$ - ld h,#0x88 + WAIT_STAT + ld a,(bc) + ld (hl+),a + inc bc + + WAIT_STAT + ld a,(bc) + ld (hl),a + inc bc + + inc l + jr nz,2$ + inc h + ld a,h ; Special wrap-around + cp #0x98 + jr nz,2$ + ld h,#0x88 2$: - dec e - jr nz,1$ - dec d - bit 7,d ; -1? - jr z,1$ - ret - - ; Copy a set of compressed (8 bytes/cell) tiles to VRAM - ; Sets the foreground and background colours based on the current - ; font colours - ; Entry: - ; From (BC) to (HL), length (DE) where DE = #cells * 8 - ; Uses the current fg_colour and bg_colour fields + dec e + jr nz,1$ + dec d + bit 7,d ; -1? + jr z,1$ + ret + + ; Copy a set of compressed (8 bytes/cell) tiles to VRAM + ; Sets the foreground and background colours based on the current + ; font colours + ; Entry: + ; From (BC) to (HL), length (DE) where DE = #cells * 8 + ; Uses the current fg_colour and bg_colour fields font_copy_compressed:: - ld a,d - or e - ret z ; Do nothing - - ld a,h - cp #0x98 ; Take care of the 97FF -> 8800 wrap around - jr c,font_copy_compressed_loop - sub #0x98-0x88 - ld h,a + ld a,d + or e + ret z ; Do nothing + + ld a,h + cp #0x98 ; Take care of the 97FF -> 8800 wrap around + jr c,font_copy_compressed_loop + sub #0x98-0x88 + ld h,a font_copy_compressed_loop: - push de - ld a,(bc) - ld e,a - inc bc - push bc - - ld bc,#0 - ; Do the background colour first - ld a,(.bg_colour) - bit 0,a - jr z,font_copy_compressed_bg_grey1 - ld b,#0xFF + push de + ld a,(bc) + ld e,a + inc bc + push bc + + ld bc,#0 + ; Do the background colour first + ld a,(.bg_colour) + bit 0,a + jr z,font_copy_compressed_bg_grey1 + ld b,#0xFF font_copy_compressed_bg_grey1: - bit 1,a - jr z,font_copy_compressed_bg_grey2 - ld c,#0xFF + bit 1,a + jr z,font_copy_compressed_bg_grey2 + ld c,#0xFF font_copy_compressed_bg_grey2: - ; BC contains the background colour - ; Compute what xoring we need to do to get the correct fg colour - ld d,a - ld a,(.fg_colour) - xor d - ld d,a - - bit 0,d - jr z,font_copy_compressed_grey1 - ld a,e - xor b - ld b,a + ; BC contains the background colour + ; Compute what xoring we need to do to get the correct fg colour + ld d,a + ld a,(.fg_colour) + xor d + ld d,a + + bit 0,d + jr z,font_copy_compressed_grey1 + ld a,e + xor b + ld b,a font_copy_compressed_grey1: - bit 1,d - jr z,font_copy_compressed_grey2 - ld a,e - xor c - ld c,a + bit 1,d + jr z,font_copy_compressed_grey2 + ld a,e + xor c + ld c,a font_copy_compressed_grey2: - WAIT_STAT + WAIT_STAT - ld (hl),b - inc l ; can't overflow here - ld (hl),c - inc hl + ld (hl),b + inc l ; can't overflow here + ld (hl),c + inc hl - ld a,h ; Take care of the 97FFF -> 8800 wrap around - cp #0x98 - jr nz,1$ - ld h,#0x88 + ld a,h ; Take care of the 97FFF -> 8800 wrap around + cp #0x98 + jr nz,1$ + ld h,#0x88 1$: - pop bc - pop de - dec de - ld a,d - or e - jr nz,font_copy_compressed_loop - ret - + pop bc + pop de + dec de + ld a,d + or e + jr nz,font_copy_compressed_loop + ret + ; Load the font HL font_load:: - call .display_off - push hl + call .display_off + push hl - ; Find the first free font entry - ld hl,#font_table+sfont_handle_font - ld b,#.MAX_FONTS + ; Find the first free font entry + ld hl,#font_table+sfont_handle_font + ld b,#.MAX_FONTS font_load_find_slot: - ld a,(hl) ; Check to see if this entry is free - inc hl ; Free is 0000 for the font pointer - or (hl) - cp #0 - jr z,font_load_found - - inc hl - inc hl - dec b - jr nz,font_load_find_slot - pop hl - ld hl,#0 - jr font_load_exit ; Couldn't find a free space + ld a,(hl) ; Check to see if this entry is free + inc hl ; Free is 0000 for the font pointer + or (hl) + cp #0 + jr z,font_load_found + + inc hl + inc hl + dec b + jr nz,font_load_find_slot + pop hl + ld hl,#0 + jr font_load_exit ; Couldn't find a free space font_load_found: - ; HL points to the end of the free font table entry - pop de - ld (hl),d ; Copy across the font struct pointer - dec hl - ld (hl),e - - ld a,(font_first_free_tile) - dec hl - ld (hl),a - - push hl - call font_set ; Set this new font to be the default - - ; Only copy the tiles in if were in text mode - ld a,(.mode) - and #.T_MODE - - call nz,font_copy_current - - ; Increase the 'first free tile' counter - ld hl,#font_current+sfont_handle_font - ld a,(hl+) - ld h,(hl) - ld l,a - - inc hl ; Number of tiles used - ld a,(font_first_free_tile) - add a,(hl) - ld (font_first_free_tile),a - - pop hl ; Return font setup in HL + ; HL points to the end of the free font table entry + pop de + ld (hl),d ; Copy across the font struct pointer + dec hl + ld (hl),e + + ld a,(font_first_free_tile) + dec hl + ld (hl),a + + push hl + call font_set ; Set this new font to be the default + + ; Only copy the tiles in if were in text mode + ld a,(.mode) + and #.T_MODE + + call nz,font_copy_current + + ; Increase the 'first free tile' counter + ld hl,#font_current+sfont_handle_font + ld a,(hl+) + ld h,(hl) + ld l,a + + inc hl ; Number of tiles used + ld a,(font_first_free_tile) + add a,(hl) + ld (font_first_free_tile),a + + pop hl ; Return font setup in HL font_load_exit: - ;; Turn the screen on - LDH A,(.LCDC) - OR #0b10000001 ; LCD = On - ; BG = On - AND #0b11100111 ; BG Chr = 0x8800 - ; BG Bank = 0x9800 - LDH (.LCDC),A - - RET - - ; Copy the tiles from the current font into VRAM -font_copy_current:: - ; Find the current font data - ld hl,#font_current+sfont_handle_font - ld a,(hl+) - ld h,(hl) - ld l,a - - inc hl ; Points to the 'tiles required' entry - ld a,(hl-) - ld d,#0 - rla ; Multiple DE by 8 - rl d - rla - rl d - rla - rl d - ld e, a ; DE has the length of the tile data - - ld a,(hl) ; Get the flags - push af - and #3 ; Only lower 2 bits set encoding table size - - ld bc,#128 - cp #FONT_128ENCODING ; 0 for 256 char encoding table, 1 for 128 char - jr z,font_copy_current_copy - - ld bc,#0 - cp #FONT_NOENCODING - jr z,font_copy_current_copy - - ld bc,#256 ; Must be 256 element encoding + ;; Turn the screen on + LDH A,(.LCDC) + OR #(LCDCF_ON | LCDCF_BGON) + AND #~(LCDCF_BG9C00 | LCDCF_BG8000) + LDH (.LCDC),A + + RET + + ; Copy the tiles from the current font into VRAM +font_copy_current:: + ; Find the current font data + ld hl,#font_current+sfont_handle_font + ld a,(hl+) + ld h,(hl) + ld l,a + + inc hl ; Points to the 'tiles required' entry + ld a,(hl-) + ld d,#0 + rla ; Multiple DE by 8 + rl d + rla + rl d + rla + rl d + ld e, a ; DE has the length of the tile data + + ld a,(hl) ; Get the flags + push af + and #3 ; Only lower 2 bits set encoding table size + + ld bc,#128 + cp #FONT_128ENCODING ; 0 for 256 char encoding table, 1 for 128 char + jr z,font_copy_current_copy + + ld bc,#0 + cp #FONT_NOENCODING + jr z,font_copy_current_copy + + ld bc,#256 ; Must be 256 element encoding font_copy_current_copy: - inc hl - inc hl ; Points to the start of the encoding table - add hl,bc - ld c,l - ld b,h ; BC points to the start of the tile data - - ; Find the offset in VRAM for this font - ld a,(font_current+sfont_handle_first_tile) ; First tile used for this font - swap a - ld l,a - and #0x0f - ld h,a - ld a, l - and #0xf0 - ld l, a - - ld a,#0x90 ; Tile 0 is at 9000h - add a,h - ld h,a - ; Is this font compressed? - pop af ; Recover flags - bit FONT_BCOMPRESSED,a - ; Do the jump in a mildly different way - jp z,font_copy_uncompressed - jp font_copy_compressed - - ; Set the current font to HL + inc hl + inc hl ; Points to the start of the encoding table + add hl,bc + ld c,l + ld b,h ; BC points to the start of the tile data + + ; Find the offset in VRAM for this font + ld a,(font_current+sfont_handle_first_tile) ; First tile used for this font + swap a + ld l,a + and #0x0f + ld h,a + ld a, l + and #0xf0 + ld l, a + + ld a,#0x90 ; Tile 0 is at 9000h + add a,h + ld h,a + ; Is this font compressed? + pop af ; Recover flags + bit FONT_BCOMPRESSED,a + ; Do the jump in a mildly different way + jp z,font_copy_uncompressed + jp font_copy_compressed + + ; Set the current font to HL font_set:: - ld a,(hl+) - ld (font_current),a - ld a,(hl+) - ld (font_current+1),a - ld a,(hl+) - ld (font_current+2),a - ret - - ;; Print a character with interpretation + ld a,(hl+) + ld (font_current),a + ld a,(hl+) + ld (font_current+1),a + ld a,(hl+) + ld (font_current+2),a + ret + + ;; Print a character with interpretation .put_char:: - ; See if it's a special char - cp #.CR - jr nz,1$ - - ; Now see if were checking special chars - push af - ld a,(.mode) - and #.M_NO_INTERP - jr nz,2$ - call .cr_curs - pop af - ret + ; See if it's a special char + cp #.CR + jr nz,1$ + + ; Now see if were checking special chars + push af + ld a,(.mode) + and #.M_NO_INTERP + jr nz,2$ + call .cr_curs + pop af + ret 2$: - pop af + pop af 1$: - call .set_char - jp .adv_curs + call .set_char + jp .adv_curs - ;; Print a character without interpretation + ;; Print a character without interpretation .out_char:: - call .set_char - jp .adv_curs + call .set_char + jp .adv_curs - ;; Delete a character + ;; Delete a character .del_char:: - call .rew_curs - ld a,#.SPACE - jp .set_char + call .rew_curs + ld a,#.SPACE + jp .set_char - ;; Print the character in A + ;; Print the character in A .set_char: - push af - ld a,(font_current+2) - ; Must be non-zero if the font system is setup (cant have a font in page zero) - or a - jr nz,3$ - - ; Font system is not yet setup - init it and copy in the ibm font - ; Kind of a compatibility mode - call _font_init - - ; Need all of the tiles - xor a - ld (font_first_free_tile),a - - call _font_load_ibm + push af + ld a,(font_current+2) + ; Must be non-zero if the font system is setup (cant have a font in page zero) + or a + jr nz,3$ + + ; Font system is not yet setup - init it and copy in the ibm font + ; Kind of a compatibility mode + call _font_init + + ; Need all of the tiles + xor a + ld (font_first_free_tile),a + + call _font_load_ibm 3$: - pop af - push bc - push de - push hl - ; Compute which tile maps to this character - ld e,a - ld hl,#font_current+sfont_handle_font - ld a,(hl+) - ld h,(hl) - ld l,a - ld a,(hl+) - and #3 - cp #FONT_NOENCODING - jr z,set_char_no_encoding - inc hl - ; Now at the base of the encoding table - ; E is set above - ld d,#0 - add hl,de - ld e,(hl) ; That's the tile! + pop af + push bc + push de + push hl + ; Compute which tile maps to this character + ld e,a + ld hl,#font_current+sfont_handle_font + ld a,(hl+) + ld h,(hl) + ld l,a + ld a,(hl+) + and #3 + cp #FONT_NOENCODING + jr z,set_char_no_encoding + inc hl + ; Now at the base of the encoding table + ; E is set above + ld d,#0 + add hl,de + ld e,(hl) ; That's the tile! set_char_no_encoding: - ld a,(font_current+0) - add a,e - ld e,a - - LD A,(.cury) ; Y coordinate - LD L,A - LD H,#0x00 - ADD HL,HL - ADD HL,HL - ADD HL,HL - ADD HL,HL - ADD HL,HL - LD A,(.curx) ; X coordinate - LD C,A - LD B,#0x00 - ADD HL,BC - LD BC,#0x9800 - ADD HL,BC - - WAIT_STAT - - LD (HL),E - POP HL - POP DE - POP BC - RET - - .area _CODE -_putchar:: ; Banked - PUSH BC - LDA HL,.BANKOV+2(SP); Skip return address - LD A,(HL) ; A = c - CALL .put_char - POP BC - RET - -_setchar:: ; Banked - PUSH BC - LDA HL,.BANKOV+2(SP); Skip return address - LD A,(HL) ; A = c - CALL .set_char - POP BC - RET - - .area _BASE + ld a,(font_current+0) + add a,e + ld e,a + + LD A,(.cury) ; Y coordinate + LD L,A + LD H,#0x00 + ADD HL,HL + ADD HL,HL + ADD HL,HL + ADD HL,HL + ADD HL,HL + LD A,(.curx) ; X coordinate + LD C,A + LD B,#0x00 + ADD HL,BC + LD BC,#0x9800 + ADD HL,BC + + WAIT_STAT + + LD (HL),E + POP HL + POP DE + POP BC + RET + + .area _CODE +_putchar:: ; Banked + PUSH BC + LDA HL,.BANKOV+2(SP); Skip return address + LD A,(HL) ; A = c + CALL .put_char + POP BC + RET + +_setchar:: ; Banked + PUSH BC + LDA HL,.BANKOV+2(SP); Skip return address + LD A,(HL) ; A = c + CALL .set_char + POP BC + RET + + .area _BASE _font_load:: - push bc - LDA HL,4(SP) ; Skip return address and bc - LD A,(HL) ; A = c - inc hl - ld h,(hl) - ld l,a - call font_load - push hl - pop de ; Return in DE - pop bc - ret + push bc + LDA HL,4(SP) ; Skip return address and bc + LD A,(HL) ; A = c + inc hl + ld h,(hl) + ld l,a + call font_load + push hl + pop de ; Return in DE + pop bc + ret _font_set:: - push bc - LDA HL,4(SP) ; Skip return address - LD A,(HL) ; A = c - inc hl - ld h,(hl) - ld l,a - call font_set - pop bc - ld de,#0 ; Always good... - ret + push bc + LDA HL,4(SP) ; Skip return address + LD A,(HL) ; A = c + inc hl + ld h,(hl) + ld l,a + call font_set + pop bc + ld de,#0 ; Always good... + ret _font_init:: - push bc - .globl .tmode + push bc + .globl .tmode - call .tmode + call .tmode - xor a - ld (font_first_free_tile),a + xor a + ld (font_first_free_tile),a - ; Clear the font table - ld hl,#font_table - ld b,#sfont_handle_sizeof*.MAX_FONTS + ; Clear the font table + ld hl,#font_table + ld b,#sfont_handle_sizeof*.MAX_FONTS 1$: - ld (hl+),a - dec b - jr nz,1$ - ld a,#3 - ld (.fg_colour),a - ld a,#0 - ld (.bg_colour),a - - call .cls - pop bc - ret - + ld (hl+),a + dec b + jr nz,1$ + ld a,#3 + ld (.fg_colour),a + ld a,#0 + ld (.bg_colour),a + + call .cls + pop bc + ret + _cls:: -.cls:: - PUSH DE - PUSH HL - LD HL,#0x9800 - LD E,#0x20 ; E = height +.cls:: + PUSH DE + PUSH HL + LD HL,#0x9800 + LD E,#0x20 ; E = height 1$: - LD D,#0x20 ; D = width + LD D,#0x20 ; D = width 2$: - WAIT_STAT - - LD (HL),#.SPACE ; Always clear - INC HL - DEC D - JR NZ,2$ - DEC E - JR NZ,1$ - POP HL - POP DE - RET - - .area _CODE - ; Support routines -_gotoxy:: ; Banked - lda hl,.BANKOV(sp) - ld a,(hl+) - ld (.curx),a - ld a,(hl) - ld (.cury),a - ret + WAIT_STAT + + LD (HL),#.SPACE ; Always clear + INC HL + DEC D + JR NZ,2$ + DEC E + JR NZ,1$ + POP HL + POP DE + RET + + .area _CODE + ; Support routines +_gotoxy:: ; Banked + lda hl,.BANKOV(sp) + ld a,(hl+) + ld (.curx),a + ld a,(hl) + ld (.cury),a + ret _posx:: - LD A,(.mode) ; Banked - AND #.T_MODE - JR NZ,1$ - PUSH BC - CALL .tmode - POP BC + LD A,(.mode) ; Banked + AND #.T_MODE + JR NZ,1$ + PUSH BC + CALL .tmode + POP BC 1$: - LD A,(.curx) - LD E,A - RET - -_posy:: ; Banked - LD A,(.mode) - AND #.T_MODE - JR NZ,1$ - PUSH BC - CALL .tmode - POP BC + LD A,(.curx) + LD E,A + RET + +_posy:: ; Banked + LD A,(.mode) + AND #.T_MODE + JR NZ,1$ + PUSH BC + CALL .tmode + POP BC 1$: - LD A,(.cury) - LD E,A - RET + LD A,(.cury) + LD E,A + RET - .area _BASE - ;; Rewind the cursor + .area _BASE + ;; Rewind the cursor .rew_curs: - PUSH HL - LD HL,#.curx ; X coordinate - XOR A - CP (HL) - JR Z,1$ - DEC (HL) - JR 99$ + PUSH HL + LD HL,#.curx ; X coordinate + XOR A + CP (HL) + JR Z,1$ + DEC (HL) + JR 99$ 1$: - LD (HL),#.MAXCURSPOSX - LD HL,#.cury ; Y coordinate - XOR A - CP (HL) - JR Z,99$ - DEC (HL) + LD (HL),#.MAXCURSPOSX + LD HL,#.cury ; Y coordinate + XOR A + CP (HL) + JR Z,99$ + DEC (HL) 99$: - POP HL - RET + POP HL + RET .cr_curs:: - PUSH HL - XOR A - LD (.curx),A - LD HL,#.cury ; Y coordinate - LD A,#.MAXCURSPOSY - CP (HL) - JR Z,2$ - INC (HL) - JR 99$ + PUSH HL + XOR A + LD (.curx),A + LD HL,#.cury ; Y coordinate + LD A,#.MAXCURSPOSY + CP (HL) + JR Z,2$ + INC (HL) + JR 99$ 2$: - CALL .scroll + CALL .scroll 99$: - POP HL - RET + POP HL + RET .adv_curs:: - PUSH HL - LD HL,#.curx ; X coordinate - LD A,#.MAXCURSPOSX - CP (HL) - JR Z,1$ - INC (HL) - JR 99$ + PUSH HL + LD HL,#.curx ; X coordinate + LD A,#.MAXCURSPOSX + CP (HL) + JR Z,1$ + INC (HL) + JR 99$ 1$: - LD (HL),#0x00 - LD HL,#.cury ; Y coordinate - LD A,#.MAXCURSPOSY - CP (HL) - JR Z,2$ - INC (HL) - JR 99$ + LD (HL),#0x00 + LD HL,#.cury ; Y coordinate + LD A,#.MAXCURSPOSY + CP (HL) + JR Z,2$ + INC (HL) + JR 99$ 2$: - ;; See if scrolling is disabled - LD A,(.mode) - AND #.M_NO_SCROLL - JR Z,3$ - ;; Nope - reset the cursor to (0,0) - XOR A - LD (.cury),A - LD (.curx),A - JR 99$ -3$: - CALL .scroll + ;; See if scrolling is disabled + LD A,(.mode) + AND #.M_NO_SCROLL + JR Z,3$ + ;; Nope - reset the cursor to (0,0) + XOR A + LD (.cury),A + LD (.curx),A + JR 99$ +3$: + CALL .scroll 99$: - POP HL - RET + POP HL + RET - ;; Scroll the whole screen + ;; Scroll the whole screen .scroll: - PUSH BC - PUSH DE - PUSH HL - LD HL,#0x9800 - LD BC,#0x9800+0x20 ; BC = next line - LD E,#0x20-0x01 ; E = height - 1 + PUSH BC + PUSH DE + PUSH HL + LD HL,#0x9800 + LD BC,#0x9800+0x20 ; BC = next line + LD E,#0x20-0x01 ; E = height - 1 1$: - LD D,#0x20 ; D = width + LD D,#0x20 ; D = width 2$: - WAIT_STAT - LD A,(BC) - LD (HL+),A - INC BC + WAIT_STAT + LD A,(BC) + LD (HL+),A + INC BC - DEC D - JR NZ,2$ - DEC E - JR NZ,1$ + DEC D + JR NZ,2$ + DEC E + JR NZ,1$ - LD D,#0x20 + LD D,#0x20 3$: - WAIT_STAT - LD A,#.SPACE - LD (HL+),A - DEC D - JR NZ,3$ - - POP HL - POP DE - POP BC - RET - - .area _BSS -.curx:: ; Cursor position - .ds 0x01 + WAIT_STAT + LD A,#.SPACE + LD (HL+),A + DEC D + JR NZ,3$ + + POP HL + POP DE + POP BC + RET + + .area _BSS +.curx:: ; Cursor position + .ds 0x01 .cury:: - .ds 0x01 + .ds 0x01 - .area _BASE + .area _BASE - .globl .drawing_vbl - .globl .drawing_lcd - .globl .int_0x40 - .globl .int_0x48 - .globl .remove_int + .globl .drawing_vbl + .globl .drawing_lcd + .globl .int_0x40 + .globl .int_0x48 + .globl .remove_int - ;; Enter text mode + ;; Enter text mode .tmode:: - DI ; Disable interrupts - - ;; Turn the screen off - LDH A,(.LCDC) - BIT 7,A - JR Z,1$ - - ;; Turn the screen off - CALL .display_off - - ;; Remove any interrupts setup by the drawing routine - LD BC,#.drawing_vbl - LD HL,#.int_0x40 - CALL .remove_int - LD BC,#.drawing_lcd - LD HL,#.int_0x48 - CALL .remove_int + DI ; Disable interrupts + + ;; Turn the screen off + LDH A,(.LCDC) + AND #LCDCF_ON + JR Z,1$ + + ;; Turn the screen off + CALL .display_off + + ;; Remove any interrupts setup by the drawing routine + LD BC,#.drawing_vbl + LD HL,#.int_0x40 + CALL .remove_int + LD BC,#.drawing_lcd + LD HL,#.int_0x48 + CALL .remove_int 1$: - CALL .tmode_out + CALL .tmode_out - ;; Turn the screen on - LDH A,(.LCDC) - OR #0b10000001 ; LCD = On - ; BG = On - AND #0b11100111 ; BG Chr = 0x8800 - ; BG Bank = 0x9800 - LDH (.LCDC),A + ;; Turn the screen on + LDH A,(.LCDC) + OR #(LCDCF_ON | LCDCF_BGON) + AND #~(LCDCF_BG9C00 | LCDCF_BG8000) + LDH (.LCDC),A - EI ; Enable interrupts + EI ; Enable interrupts - RET + RET - ;; Text mode (out only) + ;; Text mode (out only) .tmode_out:: - XOR A - LD (.curx),A - LD (.cury),A + XOR A + LD (.curx),A + LD (.cury),A - ;; Clear screen - CALL .cls + ;; Clear screen + CALL .cls - LD A,#.T_MODE - LD (.mode),A + LD A,#.T_MODE + LD (.mode),A - RET + RET diff --git a/gbdk-lib/libc/gb/gb_decompress_tiles.s b/gbdk-lib/libc/gb/gb_decompress_tiles.s @@ -24,7 +24,7 @@ _gb_decompress_bkg_data:: _gb_decompress_win_data:: ld d, #0x90 ldh a, (.LCDC) - bit 4, a + and #LCDCF_BG8000 jr z, .load_params _gb_decompress_sprite_data:: ld d, #0x80 diff --git a/gbdk-lib/libc/gb/get_addr.s b/gbdk-lib/libc/gb/get_addr.s @@ -4,13 +4,13 @@ _get_win_xy_addr:: ldh a, (.LCDC) - bit 6, a + and #LCDCF_WIN9C00 jr z, .is98 jr .is9c _get_bkg_xy_addr:: ldh a, (.LCDC) - bit 3, a + and #LCDCF_BG9C00 jr nz, .is9c .is98: ld d, #0x98 ; DE = origin diff --git a/gbdk-lib/libc/gb/get_data.s b/gbdk-lib/libc/gb/get_data.s @@ -1,121 +1,121 @@ - .include "global.s" + .include "global.s" - .globl .copy_vram + .globl .copy_vram - ;; BANKED: checked - .area _BASE + ;; BANKED: checked + .area _BASE _get_bkg_data:: _get_win_data:: - LDH A,(.LCDC) - BIT 4,A - JP NZ,_get_sprite_data - - PUSH BC - - LDA HL,7(SP) ; Skip return address and registers - LD A,(HL-) ; BC = data - LD B, A - LD A,(HL-) - LD C, A - LD A,(HL-) ; E = nb_tiles - LD E, A - LD L,(HL) ; L = first_tile - PUSH HL - - XOR A - OR E ; Is nb_tiles == 0? - JR NZ,1$ - LD DE,#0x1000 ; DE = nb_tiles = 256 - JR 2$ + LDH A,(.LCDC) + AND #LCDCF_BG8000 + JP NZ,_get_sprite_data + + PUSH BC + + LDA HL,7(SP) ; Skip return address and registers + LD A,(HL-) ; BC = data + LD B, A + LD A,(HL-) + LD C, A + LD A,(HL-) ; E = nb_tiles + LD E, A + LD L,(HL) ; L = first_tile + PUSH HL + + XOR A + OR E ; Is nb_tiles == 0? + JR NZ,1$ + LD DE,#0x1000 ; DE = nb_tiles = 256 + JR 2$ 1$: - LD H,#0x00 ; HL = nb_tiles - LD L,E - ADD HL,HL ; HL *= 16 - ADD HL,HL - ADD HL,HL - ADD HL,HL - LD D,H ; DE = nb_tiles - LD E,L + LD H,#0x00 ; HL = nb_tiles + LD L,E + ADD HL,HL ; HL *= 16 + ADD HL,HL + ADD HL,HL + ADD HL,HL + LD D,H ; DE = nb_tiles + LD E,L 2$: - POP HL ; HL = first_tile - LD A,L - RLCA ; Sign extend (patterns have signed numbers) - SBC A - LD H,A - ADD HL,HL ; HL *= 16 - ADD HL,HL - ADD HL,HL - ADD HL,HL - - PUSH BC - LD BC,#0x9000 - ADD HL,BC - POP BC - -3$: ; Special version of '.copy_vram' - BIT 3,H ; Bigger than 0x9800 - JR Z,4$ - BIT 4,H - JR Z,4$ - RES 4,H ; Switch to 0x8800 + POP HL ; HL = first_tile + LD A,L + RLCA ; Sign extend (patterns have signed numbers) + SBC A + LD H,A + ADD HL,HL ; HL *= 16 + ADD HL,HL + ADD HL,HL + ADD HL,HL + + PUSH BC + LD BC,#0x9000 + ADD HL,BC + POP BC + +3$: ; Special version of '.copy_vram' + BIT 3,H ; Bigger than 0x9800 + JR Z,4$ + BIT 4,H + JR Z,4$ + RES 4,H ; Switch to 0x8800 4$: - WAIT_STAT + WAIT_STAT - LD A,(HL+) - LD (BC),A - INC BC - DEC DE - LD A,D - OR E - JR NZ,3$ + LD A,(HL+) + LD (BC),A + INC BC + DEC DE + LD A,D + OR E + JR NZ,3$ - POP BC - RET + POP BC + RET _get_sprite_data:: - PUSH BC - - LDA HL,7(SP) ; Skip return address and registers - LD A,(HL-) ; BC = data - LD B, A - LD A,(HL-) - LD C, A - LD A,(HL-) ; E = nb_tiles - LD E, A - LD L,(HL) ; L = first_tile - PUSH HL - - XOR A - OR E ; Is nb_tiles == 0? - JR NZ,1$ - LD DE,#0x1000 ; DE = nb_tiles = 256 - JR 2$ + PUSH BC + + LDA HL,7(SP) ; Skip return address and registers + LD A,(HL-) ; BC = data + LD B, A + LD A,(HL-) + LD C, A + LD A,(HL-) ; E = nb_tiles + LD E, A + LD L,(HL) ; L = first_tile + PUSH HL + + XOR A + OR E ; Is nb_tiles == 0? + JR NZ,1$ + LD DE,#0x1000 ; DE = nb_tiles = 256 + JR 2$ 1$: - LD H,#0x00 ; HL = nb_tiles - LD L,E - ADD HL,HL ; HL *= 16 - ADD HL,HL - ADD HL,HL - ADD HL,HL - LD D,H ; DE = nb_tiles - LD E,L + LD H,#0x00 ; HL = nb_tiles + LD L,E + ADD HL,HL ; HL *= 16 + ADD HL,HL + ADD HL,HL + ADD HL,HL + LD D,H ; DE = nb_tiles + LD E,L 2$: - POP HL ; HL = first_tile - LD L,A - ADD HL,HL ; HL *= 16 - ADD HL,HL - ADD HL,HL - ADD HL,HL - - PUSH BC - LD BC,#0x8000 - ADD HL,BC - LD B,H - LD C,L - POP HL - - CALL .copy_vram - - POP BC - RET + POP HL ; HL = first_tile + LD L,A + ADD HL,HL ; HL *= 16 + ADD HL,HL + ADD HL,HL + ADD HL,HL + + PUSH BC + LD BC,#0x8000 + ADD HL,BC + LD B,H + LD C,L + POP HL + + CALL .copy_vram + + POP BC + RET diff --git a/gbdk-lib/libc/gb/get_tile.s b/gbdk-lib/libc/gb/get_tile.s @@ -13,12 +13,12 @@ _get_vram_byte:: _get_win_tile_xy:: ldh a,(.LCDC) - bit 6,a + and #LCDCF_WIN9C00 jr z,.is98 jr .is9c _get_bkg_tile_xy:: ldh a,(.LCDC) - bit 3,a + and #LCDCF_BG9C00 jr nz,.is9c .is98: ld d,#0x98 ; DE = origin diff --git a/gbdk-lib/libc/gb/get_xy_t.s b/gbdk-lib/libc/gb/get_xy_t.s @@ -1,87 +1,87 @@ - .include "global.s" + .include "global.s" - ;; BANKED: checked - .area _BASE + ;; BANKED: checked + .area _BASE - ;; Store window tile table into (BC) at xy = DE of size WH = HL + ;; Store window tile table into (BC) at xy = DE of size WH = HL .get_xy_wtt:: - PUSH HL ; Store WH - LDH A,(.LCDC) - BIT 6,A - JR Z,.is98 - JR .is9c - ;; Store background tile table into (BC) at XY = DE of size WH = HL + PUSH HL ; Store WH + LDH A,(.LCDC) + AND #LCDCF_WIN9C00 + JR Z,.is98 + JR .is9c + ;; Store background tile table into (BC) at XY = DE of size WH = HL .get_xy_btt:: - PUSH HL ; Store WH - LDH A,(.LCDC) - BIT 3,A - JR NZ,.is9c + PUSH HL ; Store WH + LDH A,(.LCDC) + AND #LCDCF_BG9C00 + JR NZ,.is9c .is98: - LD HL,#0x9800 - JR .get_xy_tt + LD HL,#0x9800 + JR .get_xy_tt .is9c: - LD HL,#0x9C00 - - ;; Store background tile table into (BC) at XY = DE, size WH on stack, from vram from address (HL) + LD HL,#0x9C00 + + ;; Store background tile table into (BC) at XY = DE, size WH on stack, from vram from address (HL) .get_xy_tt:: - PUSH BC ; Store source + PUSH BC ; Store source - SWAP E - RLC E - LD A,E - AND #0x03 - ADD H - LD B,A - LD A,#0xE0 - AND E - ADD D - LD C,A ; dest BC = HL + 0x20 * Y + X + SWAP E + RLC E + LD A,E + AND #0x03 + ADD H + LD B,A + LD A,#0xE0 + AND E + ADD D + LD C,A ; dest BC = HL + 0x20 * Y + X - POP HL ; HL = source - POP DE ; DE = WH - PUSH DE ; store WH - PUSH BC ; store dest + POP HL ; HL = source + POP DE ; DE = WH + PUSH DE ; store WH + PUSH BC ; store dest -3$: ; Copy W tiles +3$: ; Copy W tiles - WAIT_STAT - LD A, (BC) - LD (HL+), A - - LD A, C ; inc dest and wrap around - AND #0xE0 - LD E, A - LD A, C - INC A - AND #0x1F - OR E - LD C, A + WAIT_STAT + LD A, (BC) + LD (HL+), A + + LD A, C ; inc dest and wrap around + AND #0xE0 + LD E, A + LD A, C + INC A + AND #0x1F + OR E + LD C, A - DEC D - JR NZ, 3$ + DEC D + JR NZ, 3$ - POP BC - POP DE + POP BC + POP DE - DEC E - RET Z + DEC E + RET Z - PUSH DE + PUSH DE - LD A, B ; next row and wrap around - AND #0xFC - LD E, A ; save high bits + LD A, B ; next row and wrap around + AND #0xFC + LD E, A ; save high bits - LD A,#0x20 + LD A,#0x20 - ADD C - LD C, A - ADC B - SUB C - AND #0x03 - OR E ; restore high bits - LD B, A + ADD C + LD C, A + ADC B + SUB C + AND #0x03 + OR E ; restore high bits + LD B, A - PUSH BC - - JR 3$ + PUSH BC + + JR 3$ diff --git a/gbdk-lib/libc/gb/init_tt.s b/gbdk-lib/libc/gb/init_tt.s @@ -1,53 +1,53 @@ - .include "global.s" + .include "global.s" - ;; BANKED: checked - .area _BASE + ;; BANKED: checked + .area _BASE - ;; Initialize window tile table with B + ;; Initialize window tile table with B .init_wtt:: - LDH A,(.LCDC) - BIT 6,A - JR Z,.is98 - JR .is9c - ;; Initialize background tile table with B + LDH A,(.LCDC) + AND #LCDCF_WIN9C00 + JR Z,.is98 + JR .is9c + ;; Initialize background tile table with B .init_btt:: - LDH A,(.LCDC) - BIT 3,A - JR NZ,.is9c + LDH A,(.LCDC) + AND #LCDCF_BG9C00 + JR NZ,.is9c .is98: - LD HL,#0x9800 ; HL = origin - JR .init_tt + LD HL,#0x9800 ; HL = origin + JR .init_tt .is9c: - LD HL,#0x9C00 ; HL = origin + LD HL,#0x9C00 ; HL = origin .init_tt:: - LD DE,#0x0400 ; One whole GB Screen + LD DE,#0x0400 ; One whole GB Screen .init_vram:: - SRL D - RR E - JR NC, 1$ + SRL D + RR E + JR NC, 1$ - WAIT_STAT - LD A, B - LD (HL+),A + WAIT_STAT + LD A, B + LD (HL+),A 1$: - LD A, D - OR E - RET Z - - INC D - INC E - JR 2$ + LD A, D + OR E + RET Z + + INC D + INC E + JR 2$ 3$: - WAIT_STAT - LD A, B - LD (HL+),A - LD (HL+),A + WAIT_STAT + LD A, B + LD (HL+),A + LD (HL+),A 2$: - DEC E - JR NZ, 3$ - DEC D - JR NZ, 3$ - - RET + DEC E + JR NZ, 3$ + DEC D + JR NZ, 3$ + + RET diff --git a/gbdk-lib/libc/gb/input.s b/gbdk-lib/libc/gb/input.s @@ -1,654 +1,647 @@ - .include "global.s" + .include "global.s" - ;; Note that while gets uses a pointer, the pointer had better - ;; be in non-banked RAM else bad things will happen. - ;; BANKED: checked, imperfect - - .globl .copy_vram - .globl .set_xy_wtt - .globl .mv_sprite - .globl .set_sprite_prop - .globl .set_sprite_tile - .globl .jpad - .globl .padup + ;; Note that while gets uses a pointer, the pointer had better + ;; be in non-banked RAM else bad things will happen. + ;; BANKED: checked, imperfect + + .globl .copy_vram + .globl .set_xy_wtt + .globl .mv_sprite + .globl .set_sprite_prop + .globl .set_sprite_tile + .globl .jpad + .globl .padup - .MINMSPOSX = 0x02 ; In tiles - .MINMSPOSY = 0x0A - .MAXMSPOSX = 0x11 - .MAXMSPOSY = 0x0F - .INIMSPOSX = .MINMSPOSX - .INIMSPOSY = .MINMSPOSY + .MINMSPOSX = 0x02 ; In tiles + .MINMSPOSY = 0x0A + .MAXMSPOSX = 0x11 + .MAXMSPOSY = 0x0F + .INIMSPOSX = .MINMSPOSX + .INIMSPOSY = .MINMSPOSY - .KBDWINPOSY = 0x08 ; In tiles - .KBDSIZE = 0x1006 + .KBDWINPOSY = 0x08 ; In tiles + .KBDSIZE = 0x1006 - .MSOFFSETX = 0x0C ; In pixels - .MSOFFSETY = 0x14 + .MSOFFSETX = 0x0C ; In pixels + .MSOFFSETY = 0x14 - .MINACCEL = 0x0800 - .MAXACCEL = 0x0100 + .MINACCEL = 0x0800 + .MAXACCEL = 0x0100 - .CR = 0x0A ; Unix -; .CR = 0x0D ; Dos + .CR = 0x0A ; Unix +; .CR = 0x0D ; Dos - .globl .tmode_out ; From 'output.s' - .globl .put_char - .globl .del_char - .globl .cury + .globl .tmode_out ; From 'output.s' + .globl .put_char + .globl .del_char + .globl .cury - .area _INPUT_HEADER (ABS) + .area _INPUT_HEADER (ABS) - .org .MODE_TABLE+4*.T_MODE_INOUT - JP .tmode_inout + .org .MODE_TABLE+4*.T_MODE_INOUT + JP .tmode_inout - .module Terminal + .module Terminal - .area _BSS + .area _BSS -.msx: ; Mouse position - .ds 0x01 +.msx: ; Mouse position + .ds 0x01 .msy: - .ds 0x01 -.msacc: ; Mouse acceleration - .ds 0x02 -.msstate: ; Mouse state - .ds 0x01 -.mschanged: ; Did the mouse move? - .ds 0x01 -.string_len: ; Used length of input buffer - .ds 0x01 - - .area _BASE - - ;; Enter text mode with input + .ds 0x01 +.msacc: ; Mouse acceleration + .ds 0x02 +.msstate: ; Mouse state + .ds 0x01 +.mschanged: ; Did the mouse move? + .ds 0x01 +.string_len: ; Used length of input buffer + .ds 0x01 + + .area _BASE + + ;; Enter text mode with input .tmode_inout:: - DI ; Disable interrupts + DI ; Disable interrupts - ;; Turn the screen off - LDH A,(.LCDC) - BIT 7,A - JR Z,1$ + ;; Turn the screen off + LDH A,(.LCDC) + AND #LCDCF_ON + JR Z,1$ - ;; Turn the screen off - CALL .display_off + ;; Turn the screen off + CALL .display_off 1$: - LD A,(.mode) - AND #.T_MODE - CALL Z,.tmode_out - - LD BC,#.tp1 ; Move pointer - LD HL,#0x8000 - LD DE,#.endtp1-.tp1 - CALL .copy_vram - - LD A,#<.MINACCEL ; Acceleration - LD (.msacc),A - LD A,#>.MINACCEL - LD (.msacc+1),A - - ;; Initialize window - LD BC,#.frame_tiles - LD DE,#0x140A ; 0x140A - LD HL,#0 - CALL set_recoded_win_tiles - - LD BC,#.kbdtable - LD DE,#.KBDSIZE - LD HL,#(0x20 * 2 + 2) ; X=2, Y=2 - CALL set_recoded_win_tiles - - LD A,#.MINWNDPOSX - LDH (.WX),A - LD A,#.MAXWNDPOSY ; Hide window - LDH (.WY),A - - XOR A - ;; Initialize sprite - LD C,A ; Sprite 0x00 - LD D,A ; Default sprite properties - CALL .set_sprite_prop - XOR A - LD C,A ; Sprite 0x00 - LD D,A ; Tile 0x00 - CALL .set_sprite_tile - LD A,#0b00101100 - LDH (.OBP0),A - - ;; Turn the screen on - LD A,#0b11000001 ; LCD = On - ; WindowBank = 0x9C00 - ; Window = Off - ; BG Chr = 0x8800 - ; BG Bank = 0x9800 - ; OBJ = 8x8 - ; OBJ = Off - ; BG = On - LDH (.LCDC),A - - LD A,#.T_MODE_INOUT - LD (.mode),A - - EI ; Enable interrupts - - RET + LD A,(.mode) + AND #.T_MODE + CALL Z,.tmode_out + + LD BC,#.tp1 ; Move pointer + LD HL,#0x8000 + LD DE,#.endtp1-.tp1 + CALL .copy_vram + + LD A,#<.MINACCEL ; Acceleration + LD (.msacc),A + LD A,#>.MINACCEL + LD (.msacc+1),A + + ;; Initialize window + LD BC,#.frame_tiles + LD DE,#0x140A ; 0x140A + LD HL,#0 + CALL set_recoded_win_tiles + + LD BC,#.kbdtable + LD DE,#.KBDSIZE + LD HL,#(0x20 * 2 + 2) ; X=2, Y=2 + CALL set_recoded_win_tiles + + LD A,#.MINWNDPOSX + LDH (.WX),A + LD A,#.MAXWNDPOSY ; Hide window + LDH (.WY),A + + XOR A + ;; Initialize sprite + LD C,A ; Sprite 0x00 + LD D,A ; Default sprite properties + CALL .set_sprite_prop + XOR A + LD C,A ; Sprite 0x00 + LD D,A ; Tile 0x00 + CALL .set_sprite_tile + LD A,#0b00101100 + LDH (.OBP0),A + + ;; Turn the screen on + LD A,#(LCDCF_ON | LCDCF_WIN9C00 | LCDCF_WINOFF | LCDCF_BG8800 | LCDCF_BG9800 | LCDCF_OBJ8 | LCDCF_OBJOFF | LCDCF_BGON) + LDH (.LCDC),A + + LD A,#.T_MODE_INOUT + LD (.mode),A + + EI ; Enable interrupts + + RET set_recoded_win_tiles:: - LDH A,(.LCDC) - BIT 6,A - JR Z,2$ - LD A,#0x9C - JR 3$ + LDH A,(.LCDC) + AND #LCDCF_WIN9C00 + JR Z,2$ + LD A,#0x9C + JR 3$ 2$: - LD A,#0x98 + LD A,#0x98 3$: - ADD H - LD H,A - PUSH DE - PUSH HL -4$: - LD A,(BC) - INC BC - PUSH BC - PUSH HL - - LD C,A - LD HL,#(font_current+1) ; font_current+sfont_handle_font - LD A,(HL+) - LD H,(HL) - LD L,A - LD A,(HL+) - AND #3 - CP #2 ; FONT_NOENCODING - JR Z,5$ - INC HL - LD B,#0 - ADD HL,BC - LD C,(HL) + ADD H + LD H,A + PUSH DE + PUSH HL +4$: + LD A,(BC) + INC BC + PUSH BC + PUSH HL + + LD C,A + LD HL,#(font_current+1) ; font_current+sfont_handle_font + LD A,(HL+) + LD H,(HL) + LD L,A + LD A,(HL+) + AND #3 + CP #2 ; FONT_NOENCODING + JR Z,5$ + INC HL + LD B,#0 + ADD HL,BC + LD C,(HL) 5$: - POP HL - - WAIT_STAT - LD A,C - LD (HL+),A - - POP BC - - DEC D - JR NZ,4$ - - POP HL - POP DE - - LD A,L - ADD #0x20 - LD L,A - ADC H - SUB L - LD H,A - DEC E - - PUSH DE - PUSH HL - JR NZ,4$ - - ADD SP,#4 - RET - - .area _CODE - ;; Prompt the user for a char and return it in A + POP HL + + WAIT_STAT + LD A,C + LD (HL+),A + + POP BC + + DEC D + JR NZ,4$ + + POP HL + POP DE + + LD A,L + ADD #0x20 + LD L,A + ADC H + SUB L + LD H,A + DEC E + + PUSH DE + PUSH HL + JR NZ,4$ + + ADD SP,#4 + RET + + .area _CODE + ;; Prompt the user for a char and return it in A .get_char: - PUSH BC - PUSH DE - PUSH HL - CALL .show_kbd - CALL .show_mouse + PUSH BC + PUSH DE + PUSH HL + CALL .show_kbd + CALL .show_mouse 1$: - CALL .track_mouse - CALL .update_mouse - CALL .jpad - LD D,A - AND #.A ; Is A pressed ? - JP Z,1$ - - LD A,(.msy) ; Look for char under the mouse - SUB #.MINMSPOSY - JR Z,12$ - LD E,A - XOR A + CALL .track_mouse + CALL .update_mouse + CALL .jpad + LD D,A + AND #.A ; Is A pressed ? + JP Z,1$ + + LD A,(.msy) ; Look for char under the mouse + SUB #.MINMSPOSY + JR Z,12$ + LD E,A + XOR A 11$: - ADD #.MAXMSPOSX-.MINMSPOSX+1 - DEC E - JR NZ,11$ + ADD #.MAXMSPOSX-.MINMSPOSX+1 + DEC E + JR NZ,11$ 12$: - LD E,A - LD A,(.msx) - SUB #.MINMSPOSX - ADD E - LD HL,#.kbdtable - LD B,#0x00 - LD C,A - ADD HL,BC - LD B,(HL) - - CALL .hide_mouse - CALL .hide_kbd - LD A,B - - POP HL - POP DE - POP BC - RET - - ;; Prompt the user for a string and store it in (HL) + LD E,A + LD A,(.msx) + SUB #.MINMSPOSX + ADD E + LD HL,#.kbdtable + LD B,#0x00 + LD C,A + ADD HL,BC + LD B,(HL) + + CALL .hide_mouse + CALL .hide_kbd + LD A,B + + POP HL + POP DE + POP BC + RET + + ;; Prompt the user for a string and store it in (HL) .get_string: - PUSH BC - PUSH DE - PUSH HL - CALL .show_kbd - CALL .show_bkg - CALL .show_mouse - XOR A - LD (.string_len),A + PUSH BC + PUSH DE + PUSH HL + CALL .show_kbd + CALL .show_bkg + CALL .show_mouse + XOR A + LD (.string_len),A 1$: - CALL .track_mouse - CALL .update_mouse - CALL .jpad - LD D,A - AND #.A ; Is A pressed ? - JP NZ,10$ - LD A,D - AND #.B ; Is B pressed ? - JP NZ,20$ - LD A,D - AND #.SELECT ; Is SELECT pressed ? - JP NZ,30$ - LD A,D - AND #.START ; Is START pressed ? - JR Z,1$ - CALL .padup ; Wait for button to be depressed - - LD A,#.CR - CALL .put_char - LD (HL),#0x00 - CALL .hide_mouse - CALL .hide_bkg - CALL .hide_kbd - POP HL - POP DE - POP BC - RET + CALL .track_mouse + CALL .update_mouse + CALL .jpad + LD D,A + AND #.A ; Is A pressed ? + JP NZ,10$ + LD A,D + AND #.B ; Is B pressed ? + JP NZ,20$ + LD A,D + AND #.SELECT ; Is SELECT pressed ? + JP NZ,30$ + LD A,D + AND #.START ; Is START pressed ? + JR Z,1$ + CALL .padup ; Wait for button to be depressed + + LD A,#.CR + CALL .put_char + LD (HL),#0x00 + CALL .hide_mouse + CALL .hide_bkg + CALL .hide_kbd + POP HL + POP DE + POP BC + RET 10$: - ;; Insert a character at cursor position - LD A,(.string_len) ; Check buffer length -; CP #.BUFLEN-1 ; Keep 1 char for EOS -; JR Z,13$ - INC A - LD (.string_len),A ; Update it - LD A,(.msy) ; Look for char under the mouse - SUB #.MINMSPOSY - JR Z,12$ - LD E,A - XOR A + ;; Insert a character at cursor position + LD A,(.string_len) ; Check buffer length +; CP #.BUFLEN-1 ; Keep 1 char for EOS +; JR Z,13$ + INC A + LD (.string_len),A ; Update it + LD A,(.msy) ; Look for char under the mouse + SUB #.MINMSPOSY + JR Z,12$ + LD E,A + XOR A 11$: - ADD #.MAXMSPOSX-.MINMSPOSX+1 - DEC E - JR NZ,11$ + ADD #.MAXMSPOSX-.MINMSPOSX+1 + DEC E + JR NZ,11$ 12$: - LD E,A - LD A,(.msx) - SUB #.MINMSPOSX - ADD E - PUSH HL - LD HL,#.kbdtable - LD B,#0x00 - LD C,A - ADD HL,BC - LD A,(HL) - POP HL - LD (HL+),A ; Add it into input buffer - CALL .put_char ; Print it - CALL .show_bkg ; Ensure the text is not hidden + LD E,A + LD A,(.msx) + SUB #.MINMSPOSX + ADD E + PUSH HL + LD HL,#.kbdtable + LD B,#0x00 + LD C,A + ADD HL,BC + LD A,(HL) + POP HL + LD (HL+),A ; Add it into input buffer + CALL .put_char ; Print it + CALL .show_bkg ; Ensure the text is not hidden 13$: - CALL .padup ; Wait for button to be depressed - JP 1$ + CALL .padup ; Wait for button to be depressed + JP 1$ 20$: - ;; Delete a character at cursor position - LD A,(.string_len) ; Is there any char in the buffer ? - OR A - JR Z,21$ - DEC A ; Yes - LD (.string_len),A ; Update buffer length - DEC HL - CALL .del_char + ;; Delete a character at cursor position + LD A,(.string_len) ; Is there any char in the buffer ? + OR A + JR Z,21$ + DEC A ; Yes + LD (.string_len),A ; Update buffer length + DEC HL + CALL .del_char 21$: - CALL .padup ; Wait for button to be depressed - JP 1$ + CALL .padup ; Wait for button to be depressed + JP 1$ 30$: - CALL .hide_mouse - CALL .hide_bkg - CALL .hide_kbd - CALL .padup ; Wait for button to be depressed - CALL .show_kbd - CALL .show_bkg - CALL .show_mouse - JP 1$ + CALL .hide_mouse + CALL .hide_bkg + CALL .hide_kbd + CALL .padup ; Wait for button to be depressed + CALL .show_kbd + CALL .show_bkg + CALL .show_mouse + JP 1$ .show_kbd: - PUSH BC - PUSH DE - LDH A,(.LCDC) - OR #0b00100000 ; Window = On - LDH (.LCDC),A - LD A,#.MAXWNDPOSY ; Show window + PUSH BC + PUSH DE + LDH A,(.LCDC) + OR #LCDCF_WINON ; Window = On + LDH (.LCDC),A + LD A,#.MAXWNDPOSY ; Show window 1$: - BIT 0,A ; Wait for VBL every 2 pixels (slow down) - JR NZ,2$ - LD B,A - CALL .wait_vbl_done - LD A,B + BIT 0,A ; Wait for VBL every 2 pixels (slow down) + JR NZ,2$ + LD B,A + CALL .wait_vbl_done + LD A,B 2$: - LDH (.WY),A - CP #.KBDWINPOSY*0x08 - JR Z,99$ - DEC A - JR 1$ + LDH (.WY),A + CP #.KBDWINPOSY*0x08 + JR Z,99$ + DEC A + JR 1$ 99$: - POP DE - POP BC - RET + POP DE + POP BC + RET .hide_kbd: - PUSH BC - PUSH DE - LD A,#.KBDWINPOSY*0x08+1 -1$: ; Hide window - BIT 0,A ; Wait for VBL every 2 pixels (slow down) - JR Z,2$ - LD B,A - CALL .wait_vbl_done - LD A,B + PUSH BC + PUSH DE + LD A,#.KBDWINPOSY*0x08+1 +1$: ; Hide window + BIT 0,A ; Wait for VBL every 2 pixels (slow down) + JR Z,2$ + LD B,A + CALL .wait_vbl_done + LD A,B 2$: - LDH (.WY),A - CP #.MAXWNDPOSY - JR Z,3$ - INC A - JR 1$ + LDH (.WY),A + CP #.MAXWNDPOSY + JR Z,3$ + INC A + JR 1$ 3$: - LDH A,(.LCDC) - AND #0b11011111 ; Window = Off - LDH (.LCDC),A - POP DE - POP BC - RET + LDH A,(.LCDC) + AND #~LCDCF_WINON ; Window = Off + LDH (.LCDC),A + POP DE + POP BC + RET .show_bkg: - PUSH BC - PUSH DE - LDH A,(.SCY) - LD D,A - LD A,(.cury) - SUB #.KBDWINPOSY-1 - JR C,99$ - JR Z,99$ - SLA A ; A = A * 8 - SLA A - SLA A - SUB D - JR C,99$ - JR Z,99$ - LD C,A - LDH A,(.SCY) + PUSH BC + PUSH DE + LDH A,(.SCY) + LD D,A + LD A,(.cury) + SUB #.KBDWINPOSY-1 + JR C,99$ + JR Z,99$ + SLA A ; A = A * 8 + SLA A + SLA A + SUB D + JR C,99$ + JR Z,99$ + LD C,A + LDH A,(.SCY) 1$: - BIT 0,A ; Wait for VBL every 2 pixels (slow down) - JR Z,2$ - LD B,A - CALL .wait_vbl_done - LD A,B + BIT 0,A ; Wait for VBL every 2 pixels (slow down) + JR Z,2$ + LD B,A + CALL .wait_vbl_done + LD A,B 2$: - INC A - LDH (.SCY),A - DEC C - JR Z,99$ - JR 1$ + INC A + LDH (.SCY),A + DEC C + JR Z,99$ + JR 1$ 99$: - POP DE - POP BC - RET + POP DE + POP BC + RET .hide_bkg: - LDH A,(.SCY) - OR A - RET Z - PUSH BC - PUSH DE + LDH A,(.SCY) + OR A + RET Z + PUSH BC + PUSH DE 1$: - BIT 0,A ; Wait for VBL every 2 pixels (slow down) - JR Z,2$ - LD B,A - CALL .wait_vbl_done - LD A,B + BIT 0,A ; Wait for VBL every 2 pixels (slow down) + JR Z,2$ + LD B,A + CALL .wait_vbl_done + LD A,B 2$: - DEC A - LDH (.SCY),A - JR Z,99$ - JR 1$ + DEC A + LDH (.SCY),A + JR Z,99$ + JR 1$ 99$: - POP DE - POP BC - RET + POP DE + POP BC + RET .show_mouse: - LD A,#.INIMSPOSX - LD (.msx),A - LD A,#.INIMSPOSY - LD (.msy),A - CALL .set_mouse - LDH A,(.LCDC) - OR #0b00000010 ; OBJ = On - LDH (.LCDC),A - RET + LD A,#.INIMSPOSX + LD (.msx),A + LD A,#.INIMSPOSY + LD (.msy),A + CALL .set_mouse + LDH A,(.LCDC) + OR #LCDCF_OBJON ; OBJ = On + LDH (.LCDC),A + RET .hide_mouse: - LDH A,(.LCDC) - AND #0b11111101 ; OBJ = Off - LDH (.LCDC),A - RET + LDH A,(.LCDC) + AND #~LCDCF_OBJON ; OBJ = Off + LDH (.LCDC),A + RET .track_mouse: - PUSH BC - PUSH DE - PUSH HL - XOR A - LD (.mschanged),A ; Default to no change - CALL .jpad - LD D,A - - LD HL,#.msstate - AND #.UP+.DOWN+.LEFT+.RIGHT - JR NZ,1$ - LD (HL),#0x00 ; Reset state - JP 99$ + PUSH BC + PUSH DE + PUSH HL + XOR A + LD (.mschanged),A ; Default to no change + CALL .jpad + LD D,A + + LD HL,#.msstate + AND #.UP+.DOWN+.LEFT+.RIGHT + JR NZ,1$ + LD (HL),#0x00 ; Reset state + JP 99$ 1$: - LD A,(HL) - LD (HL),#0x01 ; Set state - OR A ; Was it 0 ? - LD HL,#.msacc ; Acceleration - JR NZ,2$ - ; Yes - LD (HL),#<.MINACCEL - INC HL - LD (HL),#>.MINACCEL - JR 4$ ; Update position + LD A,(HL) + LD (HL),#0x01 ; Set state + OR A ; Was it 0 ? + LD HL,#.msacc ; Acceleration + JR NZ,2$ + ; Yes + LD (HL),#<.MINACCEL + INC HL + LD (HL),#>.MINACCEL + JR 4$ ; Update position 2$: - LD A,(HL+) - LD C, A - LD B,(HL) - DEC BC - LD A,B - OR C - JR Z,3$ - LD (HL),B - DEC HL - LD (HL),C - JP 99$ -3$: ; Set new acceleration to maximum - LD (HL),#>.MAXACCEL - DEC HL - LD (HL),#<.MAXACCEL -4$: ; Update position - LD A,#0x01 - LD (.mschanged),A - LD A,D - AND #.UP ; Is UP pressed ? - JR Z,6$ - LD A,(.msy) - CP #.MINMSPOSY - JR Z,5$ - DEC A - LD (.msy),A - JR 6$ + LD A,(HL+) + LD C, A + LD B,(HL) + DEC BC + LD A,B + OR C + JR Z,3$ + LD (HL),B + DEC HL + LD (HL),C + JP 99$ +3$: ; Set new acceleration to maximum + LD (HL),#>.MAXACCEL + DEC HL + LD (HL),#<.MAXACCEL +4$: ; Update position + LD A,#0x01 + LD (.mschanged),A + LD A,D + AND #.UP ; Is UP pressed ? + JR Z,6$ + LD A,(.msy) + CP #.MINMSPOSY + JR Z,5$ + DEC A + LD (.msy),A + JR 6$ 5$: - LD A,#.MAXMSPOSY - LD (.msy),A + LD A,#.MAXMSPOSY + LD (.msy),A 6$: - LD A,D - AND #.DOWN ; Is DOWN pressed ? - JR Z,8$ - LD A,(.msy) - CP #.MAXMSPOSY - JR Z,7$ - INC A - LD (.msy),A - JR 8$ + LD A,D + AND #.DOWN ; Is DOWN pressed ? + JR Z,8$ + LD A,(.msy) + CP #.MAXMSPOSY + JR Z,7$ + INC A + LD (.msy),A + JR 8$ 7$: - LD A,#.MINMSPOSY - LD (.msy),A + LD A,#.MINMSPOSY + LD (.msy),A 8$: - LD A,D - AND #.LEFT ; Is LEFT pressed ? - JR Z,10$ - LD A,(.msx) - CP #.MINMSPOSX - JR Z,9$ - DEC A - LD (.msx),A - JR 10$ + LD A,D + AND #.LEFT ; Is LEFT pressed ? + JR Z,10$ + LD A,(.msx) + CP #.MINMSPOSX + JR Z,9$ + DEC A + LD (.msx),A + JR 10$ 9$: - LD A,#.MAXMSPOSX - LD (.msx),A + LD A,#.MAXMSPOSX + LD (.msx),A 10$: - LD A,D - AND #.RIGHT ; Is RIGHT pressed ? - JR Z,99$ - LD A,(.msx) - CP #.MAXMSPOSX - JR Z,11$ - INC A - LD (.msx),A - JR 99$ + LD A,D + AND #.RIGHT ; Is RIGHT pressed ? + JR Z,99$ + LD A,(.msx) + CP #.MAXMSPOSX + JR Z,11$ + INC A + LD (.msx),A + JR 99$ 11$: - LD A,#.MINMSPOSX - LD (.msx),A + LD A,#.MINMSPOSX + LD (.msx),A 99$: - POP HL - POP DE - POP BC - RET + POP HL + POP DE + POP BC + RET .update_mouse: - LD A,(.mschanged) ; Did it change ? - OR A - RET Z ; No + LD A,(.mschanged) ; Did it change ? + OR A + RET Z ; No .set_mouse: - PUSH BC - PUSH DE - PUSH HL - LD C,#0x00 ; Sprite 0x00 - LD A,(.msx) - SLA A ; A = A * 8 - SLA A - SLA A - ADD #.MSOFFSETX - LD D,A - LD A,(.msy) - SLA A ; A = A * 8 - SLA A - SLA A - ADD #.MSOFFSETY - LD E,A - CALL .mv_sprite - POP HL - POP DE - POP BC - RET - -_getchar:: ; Banked - LD A,(.mode) - CP #.T_MODE_INOUT - JR Z,1$ - PUSH BC - CALL .tmode_inout - POP BC + PUSH BC + PUSH DE + PUSH HL + LD C,#0x00 ; Sprite 0x00 + LD A,(.msx) + SLA A ; A = A * 8 + SLA A + SLA A + ADD #.MSOFFSETX + LD D,A + LD A,(.msy) + SLA A ; A = A * 8 + SLA A + SLA A + ADD #.MSOFFSETY + LD E,A + CALL .mv_sprite + POP HL + POP DE + POP BC + RET + +_getchar:: ; Banked + LD A,(.mode) + CP #.T_MODE_INOUT + JR Z,1$ + PUSH BC + CALL .tmode_inout + POP BC 1$: - CALL .get_char - LD E,A - RET - -_gets:: ; Banked - LD A,(.mode) - CP #.T_MODE_INOUT - JR Z,1$ - PUSH BC - CALL .tmode_inout - POP BC + CALL .get_char + LD E,A + RET + +_gets:: ; Banked + LD A,(.mode) + CP #.T_MODE_INOUT + JR Z,1$ + PUSH BC + CALL .tmode_inout + POP BC 1$: - LDA HL,.BANKOV(SP) ; Skip return address - LD A,(HL+) - LD H,(HL) ; HL = s - LD L,A - PUSH HL - CALL .get_string - POP DE - RET - - ;; PENDING: this is unfortunate. Refed from .tmode_inout - .area _BASE + LDA HL,.BANKOV(SP) ; Skip return address + LD A,(HL+) + LD H,(HL) ; HL = s + LD L,A + PUSH HL + CALL .get_string + POP DE + RET + + ;; PENDING: this is unfortunate. Refed from .tmode_inout + .area _BASE .tp1: .pointers: - ; Tile 0x00 - .byte 0xFF,0xFF,0xFE,0x82,0xFC,0x84,0xFC,0x84,0xFE,0x82,0xFF,0xB1,0xCF,0xC9,0x87,0x87 + ; Tile 0x00 + .byte 0xFF,0xFF,0xFE,0x82,0xFC,0x84,0xFC,0x84,0xFE,0x82,0xFF,0xB1,0xCF,0xC9,0x87,0x87 .endtp1: .frame_tiles: - .byte 0x1C,0x0E,0x0E,0x0E,0x0E,0x0E,0x0E,0x0E,0x0E,0x0E,0x0E,0x0E,0x0E,0x0E,0x0E,0x0E,0x0E,0x0E,0x0E,0x1D - .byte 0x0F,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x0F - .byte 0x0F,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x0F - .byte 0x0F,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x0F - .byte 0x0F,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x0F - .byte 0x0F,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x0F - .byte 0x0F,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x0F - .byte 0x0F,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x0F - .byte 0x0F,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x0F - .byte 0x1E,0x0E,0x0E,0x0E,0x0E,0x0E,0x0E,0x0E,0x0E,0x0E,0x0E,0x0E,0x0E,0x0E,0x0E,0x0E,0x0E,0x0E,0x0E,0x1F + .byte 0x1C,0x0E,0x0E,0x0E,0x0E,0x0E,0x0E,0x0E,0x0E,0x0E,0x0E,0x0E,0x0E,0x0E,0x0E,0x0E,0x0E,0x0E,0x0E,0x1D + .byte 0x0F,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x0F + .byte 0x0F,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x0F + .byte 0x0F,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x0F + .byte 0x0F,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x0F + .byte 0x0F,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x0F + .byte 0x0F,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x0F + .byte 0x0F,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x0F + .byte 0x0F,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x0F + .byte 0x1E,0x0E,0x0E,0x0E,0x0E,0x0E,0x0E,0x0E,0x0E,0x0E,0x0E,0x0E,0x0E,0x0E,0x0E,0x0E,0x0E,0x0E,0x0E,0x1F .kbdtable: - ;; This is unfortunate. astorgb and rgbasm cant interpert: - ;; .ascii " !\"#$%&'()*+,-./" - ;; so we have to use the hex form here. - .db 0x20,0x21,0x22,0x23,0x24,0x25,0x26,0x27 - .db 0x28,0x29,0x2A,0x2B,0x2C,0x2D,0x2E,0x2F - .ascii "0123456789:" - ;; astorgb recognises the embedded ; as a comment :) - .db 0x3B - .ascii "<=>?" - .ascii "@ABCDEFGHIJKLMNO" - .ascii "PQRSTUVWXYZ[\]^_" - .ascii "`abcdefghijklmno" - .ascii "pqrstuvwxyz{|}~ " + ;; This is unfortunate. astorgb and rgbasm cant interpert: + ;; .ascii " !\"#$%&'()*+,-./" + ;; so we have to use the hex form here. + .db 0x20,0x21,0x22,0x23,0x24,0x25,0x26,0x27 + .db 0x28,0x29,0x2A,0x2B,0x2C,0x2D,0x2E,0x2F + .ascii "0123456789:" + ;; astorgb recognises the embedded ; as a comment :) + .db 0x3B + .ascii "<=>?" + .ascii "@ABCDEFGHIJKLMNO" + .ascii "PQRSTUVWXYZ[\]^_" + .ascii "`abcdefghijklmno" + .ascii "pqrstuvwxyz{|}~ " diff --git a/gbdk-lib/libc/gb/set_1bit_data.s b/gbdk-lib/libc/gb/set_1bit_data.s @@ -6,7 +6,7 @@ _set_bkg_1bit_data:: _set_win_1bit_data:: ld d, #0x90 ldh a, (.LCDC) - bit 4, a + and #LCDCF_BG8000 jr z, .copy_1bit_tiles _set_sprite_1bit_data:: ld d, #0x80 diff --git a/gbdk-lib/libc/gb/set_data.s b/gbdk-lib/libc/gb/set_data.s @@ -11,7 +11,7 @@ _set_bkg_data:: _set_win_data:: ld d, #0x90 ldh a, (.LCDC) - bit 4, a + and #LCDCF_BG8000 jr z, .copy_tiles _set_sprite_data:: ld d, #0x80 diff --git a/gbdk-lib/libc/gb/set_tile.s b/gbdk-lib/libc/gb/set_tile.s @@ -19,12 +19,12 @@ _set_vram_byte:: _set_win_tile_xy:: ldh a,(.LCDC) - bit 6,a + and #LCDCF_WIN9C00 jr z,.is98 jr .is9c _set_bkg_tile_xy:: ldh a,(.LCDC) - bit 3,a + and #LCDCF_BG9C00 jr nz,.is9c .is98: ld d,#0x98 ; DE = origin diff --git a/gbdk-lib/libc/gb/set_tile_submap.s b/gbdk-lib/libc/gb/set_tile_submap.s @@ -56,14 +56,14 @@ _set_bkg_submap:: .set_xy_win_submap:: push hl ; store wh ldh a,(.LCDC) - bit 6,a + and #LCDCF_WIN9C00 jr z,.is98 jr .is9c ;; set background tile table from (bc) at xy = de of size wh = hl .set_xy_bkg_submap:: push hl ; store wh ldh a,(.LCDC) - bit 3,a + and #LCDCF_BG9C00 jr nz,.is9c .is98: ld hl,#0x9800 diff --git a/gbdk-lib/libc/gb/set_xy_t.s b/gbdk-lib/libc/gb/set_xy_t.s @@ -1,85 +1,85 @@ - .include "global.s" + .include "global.s" - .area _BASE + .area _BASE - ;; Set window tile table from BC at XY = DE of size WH = HL + ;; Set window tile table from BC at XY = DE of size WH = HL .set_xy_wtt:: - PUSH HL ; Store WH - LDH A,(.LCDC) - BIT 6,A - JR Z,.is98 - JR .is9c - ;; Set background tile table from (BC) at XY = DE of size WH = HL + PUSH HL ; Store WH + LDH A,(.LCDC) + AND #LCDCF_WIN9C00 + JR Z,.is98 + JR .is9c + ;; Set background tile table from (BC) at XY = DE of size WH = HL .set_xy_btt:: - PUSH HL ; Store WH - LDH A,(.LCDC) - BIT 3,A - JR NZ,.is9c + PUSH HL ; Store WH + LDH A,(.LCDC) + AND #LCDCF_BG9C00 + JR NZ,.is9c .is98: - LD HL,#0x9800 - JR .set_xy_tt + LD HL,#0x9800 + JR .set_xy_tt .is9c: - LD HL,#0x9C00 - ;; Set background tile from (BC) at XY = DE, size WH on stack, to vram from address (HL) + LD HL,#0x9C00 + ;; Set background tile from (BC) at XY = DE, size WH on stack, to vram from address (HL) .set_xy_tt:: - PUSH BC ; Store source + PUSH BC ; Store source - SWAP E - RLC E - LD A,E - AND #0x03 - ADD H - LD B,A - LD A,#0xE0 - AND E - ADD D - LD C,A ; dest BC = HL + 0x20 * Y + X + SWAP E + RLC E + LD A,E + AND #0x03 + ADD H + LD B,A + LD A,#0xE0 + AND E + ADD D + LD C,A ; dest BC = HL + 0x20 * Y + X - POP HL ; HL = source - POP DE ; DE = WH - PUSH DE ; store WH - PUSH BC ; store dest + POP HL ; HL = source + POP DE ; DE = WH + PUSH DE ; store WH + PUSH BC ; store dest -3$: ; Copy W tiles +3$: ; Copy W tiles - WAIT_STAT - LD A, (HL+) - LD (BC), A - - LD A, C ; inc dest and wrap around - AND #0xE0 - LD E, A - LD A, C - INC A - AND #0x1F - OR E - LD C, A + WAIT_STAT + LD A, (HL+) + LD (BC), A + + LD A, C ; inc dest and wrap around + AND #0xE0 + LD E, A + LD A, C + INC A + AND #0x1F + OR E + LD C, A - DEC D - JR NZ, 3$ + DEC D + JR NZ, 3$ - POP BC - POP DE + POP BC + POP DE - DEC E - RET Z + DEC E + RET Z - PUSH DE + PUSH DE - LD A, B ; next row and wrap around - AND #0xFC - LD E, A ; save high bits + LD A, B ; next row and wrap around + AND #0xFC + LD E, A ; save high bits - LD A,#0x20 + LD A,#0x20 - ADD C - LD C, A - ADC B - SUB C - AND #0x03 - OR E ; restore high bits - LD B, A + ADD C + LD C, A + ADC B + SUB C + AND #0x03 + OR E ; restore high bits + LD B, A - PUSH BC - - JR 3$ + PUSH BC + + JR 3$
This webpage is intended to be an accessible preview of this repository. To get a fuller picture, clone it and use the git CLI.