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 of return register
29 @wait: bit VDC_INDEX ; busy wait until vdc is ready
35 ;;; unsigned __fastcall__ vdc_read_addr (unsigned char reg);
37 tay ; copy vdc register
38 iny ; next register is high byte of addr
40 tax ; save high byte in x return register
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);
63 jsr popa ; this mustn't touch x (libsrc/runtime/popa.s)
68 txa ; get high byte of addr
70 iny ; next vdc register is high byte of addr
75 ;;; void __fastcall__ vdc_read_mem (unsigned dest, unsigned src, unsigned n);
91 ldy #0 ; offset into dest
93 ;; first, loop over the high byte of n, 256 times
94 ldx ptr1+1 ; get high byte of n
95 beq @low ; skip if zero
103 bne @cpyhi ; have we copied 256 bytes yet?
105 inc ptr2+1 ; adjust dest pointer
107 bne @cpyhi ; read 256 more bytes
109 @low: ldx ptr1 ; get low byte of n
110 beq @done ; skip if zero
123 ;;; void __fastcall__ vdc_write_mem (unsigned dest, const void* src, unsigned n);
139 ldy #0 ; offset into dest
141 ;; first, loop over the high byte of n
142 ldx ptr1+1 ; get high byte of n
143 beq @low ; skip if zero
145 @cpyhi: bit VDC_INDEX
151 bne @cpyhi ; have we copied 256 bytes yet?
153 inc ptr2+1 ; adjust dest pointer
155 bne @cpyhi ; read 256 more bytes
157 @low: ldx ptr1 ; get low byte of n
158 beq @done ; skip if zero
171 ;;; void __fastcall__ vdc_load_thinfont (void);
179 ;; map in alternate font
185 ;; call kernal load font routine