Skip to content

Commit

Permalink
[KERNAL] New I2C batch commands (X16Community#158)
Browse files Browse the repository at this point in the history
* Initial code

* More work on initial implementation

* Bugfixes, and test implementation for interruptable batch commands

* Test: disable joystick scan, disable IRQ while sending I2C start and stop conditions

* Disable joystick scan while I2C batch command runs, fix I2C batch write

* Fix: Prevent joystick scan from driving I2C pins

* Fix bug introduced in joystick scan method

* Improve joystick scan performance

* Further joy scan speed optimization

* Added vectors to kernsup.inc

---------

Co-authored-by: mooinglemur <[email protected]>
  • Loading branch information
stefan-b-jakobsson and mooinglemur authored Oct 12, 2023
1 parent b87eff7 commit 2e97657
Show file tree
Hide file tree
Showing 10 changed files with 370 additions and 42 deletions.
1 change: 1 addition & 0 deletions cfg/kernal-x16.cfgtpl
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ SEGMENTS {
KVAR: load = KVAR, type = bss;
VARCHANNEL: load = KVAR, type = bss;
VARFONTS: load = KVAR, type = bss;
I2CMUTEX: load = I2CMUTEX, type = bss;
KVAR2: load = KVAR2, type = bss;

GDRVVEC: load = GDRVVEC, type = bss;
Expand Down
3 changes: 2 additions & 1 deletion cfg/x16.cfginc
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ ZPBASIC: start = $00D4, size = $002B; # BASIC (last byte used: $FE)

/* $0200-$02FF: always-available variables and RAM code */
KVAR: start = $0200, size = $00BB; # KERNAL
/* start = $02BB, size = $0006; # reserved for KERNAL growth */
/* start = $02BB, size = $0005; # reserved for KERNAL growth */
I2CMUTEX: start = $02C0, size = $0001; # I2C MUTEX FLAG
GRAPHVAR: start = $02C1, size = $0003; # GRAPH BANK VARS
KERNRAM: start = $02C4, size = $0020; # KERNAL RAM code
GDRVVEC: start = $02E4, size = $001C; # framebuffer driver vectors
Expand Down
2 changes: 2 additions & 0 deletions inc/kernal.inc
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,8 @@ entropy_get = $fecf

i2c_read_byte = $fec6
i2c_write_byte = $fec9
i2c_batch_read = $feb4
i2c_batch_write = $feb7

kbdbuf_peek = $febd
kbdbuf_get_modifiers = $fec0
Expand Down
3 changes: 2 additions & 1 deletion kernal/cbm/init.s
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

.feature labels_without_colons

.import cint, ramtas, ioinit, enter_basic, restor, vera_wait_ready, call_audio_init, boot_cartridge
.import cint, ramtas, ioinit, enter_basic, restor, vera_wait_ready, call_audio_init, boot_cartridge, i2c_restore

.export start

Expand All @@ -20,6 +20,7 @@ start ldx #$ff
jsr ioinit ;go initilize i/o devices
jsr ramtas ;go ram test and set
jsr restor ;go set up os vectors
jsr i2c_restore ;release I2C pins and clear mutex flag
;
jsr cint ;go initilize screen
jsr call_audio_init ;initialize audio API and HW.
Expand Down
1 change: 0 additions & 1 deletion kernal/cbm/irq.s
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
.feature labels_without_colons

.import dfltn, dflto, kbd_scan, clock_update, cinv, cbinv

.export key

.segment "IRQ"
Expand Down
4 changes: 4 additions & 0 deletions kernal/cbm/nmi.s
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ monitor = $fecc
clrch = $ffcc
.import enter_basic, cint, ioinit, restor, nminv
.import call_audio_init
.import i2c_restore
.import jsrfar

.export nnmi, timb, dbgbrk
Expand All @@ -22,6 +23,7 @@ clrch = $ffcc
; warm reset, ctrl+alt+restore, default value for (nminv)
nnmi jsr ioinit ;go initilize i/o devices
jsr restor ;go set up os vectors
jsr i2c_restore ;release I2C pins and clear mutex flag
;
jsr cint ;go initilize screen
jsr call_audio_init ;initialize audio API and HW.
Expand All @@ -33,6 +35,7 @@ nnmi jsr ioinit ;go initilize i/o devices
; timb - where system goes on a brk instruction
;
timb jsr restor ;restore system indirects
jsr i2c_restore ;release I2C pins and clear mutex flag
jsr ioinit ;restore i/o for basic
jsr cint ;restore screen for basic
jsr call_audio_init ;initialize audio API and HW.
Expand All @@ -47,4 +50,5 @@ monen
rti

dbgbrk jsr clrch
jsr i2c_restore ;release I2C pins and clear mutex flag
bra monen
Loading

0 comments on commit 2e97657

Please sign in to comment.