1 ;;; -*- tab-width: 8; -*-
2 .export _vdc_read_reg, _vdc_read_addr, _vdc_read_mem
3 .export _vdc_write_reg, _vdc_write_addr, _vdc_write_mem
4 .export _vdc_load_thinfont
10 ;;; useful documentation:
11 ;;; - 6502 instruction/addressing mode overview
12 ;;; - http://www.obelisk.me.uk/6502/index.html
13 ;;; - cc65 assembler interfacing with C
14 ;;; - https://github.com/cc65/wiki/wiki/Parameter-passing-and-calling-conventions
15 ;;; - https://github.com/cc65/wiki/wiki/Parameter-and-return-stacks
16 ;;; - https://github.com/cc65/wiki/wiki/Using-runtime-zeropage-locations-in-assembly-language
17 ;;; - Programming the VDC
18 ;;; - Chapter 10 of http: //www.pagetable.com/docs/Commodore%20128%20Programmer%27s%20Reference%20Guide.pdf
23 ;;; unsigned char __fastcall__ vdc_read_reg (unsigned char reg);
25 ldx #0 ; clear high byte
29 @wait: bit VDC_INDEX ; busy wait until vdc is ready
35 ;;; unsigned __fastcall__ vdc_read_addr (unsigned char reg);
37 tay ; save copy of vdc reg
40 dey ; set low byte vdc reg
45 ;;; void __fastcall__ vdc_write_reg (unsigned char reg, unsigned char data);
54 @wait: bit VDC_INDEX ; busy wait until vdc is ready
60 ;;; void __fastcall__ vdc_write_addr (unsigned char reg, unsigned addr);
68 txa ; get high byte of addr
73 ;;; void __fastcall__ vdc_read_mem (unsigned dest, unsigned src, unsigned n);
89 ldy #0 ; offset into dest
91 ;; first, loop over the high byte of n, 256 times
92 ldx ptr1+1 ; get high byte of n
93 beq @low ; skip if zero
101 bne @cpyhi ; have we copied 256 bytes yet?
103 inc ptr2+1 ; adjust dest pointer
105 bne @cpyhi ; read 256 more bytes
107 @low: ldx ptr1 ; get low byte of n
108 beq @done ; skip if zero
121 ;;; void __fastcall__ vdc_write_mem (unsigned dest, const void* src, unsigned n);
137 ldy #0 ; offset into dest
139 ;; first, loop over the high byte of n
140 ldx ptr1+1 ; get high byte of n
141 beq @low ; skip if zero
143 @cpyhi: bit VDC_INDEX
149 bne @cpyhi ; have we copied 256 bytes yet?
151 inc ptr2+1 ; adjust dest pointer
153 bne @cpyhi ; read 256 more bytes
155 @low: ldx ptr1 ; get low byte of n
156 beq @done ; skip if zero
169 ;;; void __fastcall__ vdc_load_thinfont (void);
177 ;; map in alternate font
183 ;; call kernal load font routine