gbdk-2020 | GameBoy Development Kit |
| download: https://git.y1.nz/archives/gbdk.tar.gz | |
| README | Files | Log | Refs | LICENSE |
gbdk-lib/libc/targets/mos6502/nes/lcd.s
1 .include "global.s"
2
3 .area GBDKOVR (PAG, OVR)
4
5 .area _ZP (PAG)
6 __lcd_scanline:: .ds 1
7
8 .area _DATA
9 .jmp_to_xyz_isr::
10 .jmp_to_TIM_isr:: .ds 3
11 .jmp_to_LCD_isr:: .ds 3
12 .jmp_to_VBL_isr:: .ds 3
13
14 .area _XINIT
15 ; .jmp_to_TIM_isr - default to OFF
16 .db 0x60
17 .dw .rts_instruction
18 ; .jmp_to_LCD_isr - default to OFF
19 .db 0x60
20 .dw .rts_instruction
21 ; .jmp_to_VBL_isr - default to ON
22 jmp .rts_instruction
23
24 .area _CODE
25 _add_TIM::
26 .add_TIM::
27 ldy #0
28 beq .add_common
29 _add_LCD::
30 .add_LCD::
31 ldy #3
32 bne .add_common
33 _add_VBL::
34 .add_VBL::
35 ldy #6
36 .add_common:
37 pha
38 stx *.tmp
39 ; Remove old handler
40 jsr .irq_call_disable
41 ; Store new handler address
42 pla
43 sta .jmp_to_xyz_isr+1,y
44 lda *.tmp
45 sta .jmp_to_xyz_isr+2,y
46 jsr .irq_call_restore
47 .rts_instruction:
48 rts
49
50 _remove_TIM::
51 .remove_TIM::
52 ldy #0
53 beq .remove_common
54 _remove_LCD::
55 .remove_LCD::
56 ldy #3
57 bne .remove_common
58 _remove_VBL::
59 .remove_VBL::
60 ldy #6
61 .remove_common:
62 ; Replace handler address with dummy address pointing to RTS instruction
63 jsr .irq_call_disable
64 lda #<.rts_instruction
65 sta .jmp_to_xyz_isr+1,y
66 lda #>.rts_instruction
67 sta .jmp_to_xyz_isr+2,y
68 jsr .irq_call_restore
69 .return_instruction:
70 rts
71
72 .irq_call_disable:
73 ; Temporarily replace JMP instruction with RTS
74 ldx .jmp_to_xyz_isr,y
75 lda #0x60
76 sta .jmp_to_xyz_isr,y
77 rts
78
79 .irq_call_restore:
80 ; Rewrite old instruction (unknown - could be JMP or RTS)
81 txa
82 sta .jmp_to_xyz_isr,y
83 rts
84
85 _set_interrupts::
86 ; TIM isr
87 lsr
88 ldx #0x60
89 bcc 0$
90 ldx #0x4C
91 0$:
92 stx .jmp_to_VBL_isr
93 ; LCD isr
94 lsr
95 ldx #0x60
96 bcc 1$
97 ldx #0x4C
98 1$:
99 stx .jmp_to_LCD_isr
100 ; VBL isr
101 lsr
102 ldx #0x60
103 bcc 2$
104 ldx #0x4C
105 2$:
106 stx .jmp_to_TIM_isr
107 rts
This webpage is intended to be an accessible preview of this repository. To get a fuller picture, clone it and use the git CLI.