1
0
mirror of https://github.com/hsoft/collapseos.git synced 2024-11-02 06:30:55 +11:00

Compare commits

...

4 Commits

Author SHA1 Message Date
Virgil Dupras
7b7e60ed4a avra: implement LD/ST
Still making great progress on sms/kbd/ps2ctl. Still matching ref
binary.
2020-05-18 22:28:58 -04:00
Virgil Dupras
6a55a04f22 sms/kbd: still advancing on ps2ctl
next step: implement ST.
2020-05-18 20:55:10 -04:00
Virgil Dupras
e0bc14e55c avra: implement BR*
Getting good! still advancing on ps2ctl in sms/kbd and still
matching reference binary.
2020-05-18 20:34:06 -04:00
Virgil Dupras
cdddfdefae avra: add a layer of indirection to FLBL!
This will make it easier to fit BR* in there.
2020-05-18 19:45:30 -04:00
8 changed files with 174 additions and 19 deletions

View File

@ -1 +1 @@
1 9 LOADR+ 1 11 LOADR+

View File

@ -5,4 +5,3 @@
: _r64c DUP 63 > IF _oor THEN ; : _r64c DUP 63 > IF _oor THEN ;
: _r256c DUP 255 > IF _oor THEN ; : _r256c DUP 255 > IF _oor THEN ;
: _Rdp ( op rd -- op', place Rd ) 4 LSHIFT OR ; : _Rdp ( op rd -- op', place Rd ) 4 LSHIFT OR ;

View File

@ -10,4 +10,4 @@
0b1111110000000000 OPRdb SBRC, 0b1111111000000000 OPRdb SBRS, 0b1111110000000000 OPRdb SBRC, 0b1111111000000000 OPRdb SBRS,
( special cases ) ( special cases )
: CLR, DUP EOR, ; : TST, DUP AND, ; : CLR, DUP EOR, ; : TST, DUP AND, ; : LSL, DUP ADD, ;

View File

@ -2,7 +2,6 @@
: _r7ffc DUP 0x7ff > IF _oor THEN ; : _r7ffc DUP 0x7ff > IF _oor THEN ;
: _raddr12 : _raddr12
PC - DUP 0< IF 0x800 + _r7ffc 0x800 OR ELSE _r7ffc THEN ; PC - DUP 0< IF 0x800 + _r7ffc 0x800 OR ELSE _r7ffc THEN ;
0xc0 CONSTANT RJMPOP : RJMP _raddr12 0xc000 OR ;
0xd0 CONSTANT RCALLOP : RCALL _raddr12 0xd000 OR ;
: RJMP, _raddr12 RJMPOP 8 LSHIFT OR A,, ; : RJMP, RJMP A,, ; : RCALL, RCALL A,, ;
: RCALL, _raddr12 RCALLOP 8 LSHIFT OR A,, ;

20
blk/669
View File

@ -1,10 +1,12 @@
( ex: L1 LBL! .. L1 @ RJMP, ) ( a -- k7, absolute addr a, relative to PC in a k7 addr )
: LBL! ( l -- ) PC SWAP ! ; : _r3fc DUP 0x3f > IF _oor THEN ;
( ex: L1 FLBL, .. RJMPOP L1 FLBL! ) : _raddr7
: FLBL, ( l -- ) LBL! 0 A,, ; PC - DUP 0< IF 0x40 + _r3fc 0x40 OR ELSE _r3fc THEN ;
: FLBL! ( op l -- ) : _brbx ( a b op -- a ) OR SWAP _raddr7 3 LSHIFT OR ;
@ DUP PC -^ 1- ( op l off ) : BRBC 0xf400 _brbx ; : BRBS 0xf000 _brbx ; : BRCC 0 BRBC ;
ROT 8 LSHIFT OR ( l op' ) : BRCS 0 BRBS ; : BREQ 1 BRBS ; : BRNE 1 BRBC ; : BRGE 4 BRBC ;
( warning: l is a PC offset, not a mem addr! ) : BRHC 5 BRBC ; : BRHS 5 BRBS ; : BRID 7 BRBC ; : BRIE 7 BRBS ;
SWAP 2 * ORG @ + ( op' addr ) ! ; : BRLO BRCS ; : BRLT 4 BRBS ; : BRMI 2 BRBS ; : BRPL 2 BRBC ;
: BRSH BRCC ; : BRTC 6 BRBC ; : BRTS 6 BRBS ; : BRVC 3 BRBC ;
: BRVS 3 BRBS ;

6
blk/670 Normal file
View File

@ -0,0 +1,6 @@
0b11100 CONSTANT X 0b01000 CONSTANT Y 0b00000 CONSTANT Z
0b11101 CONSTANT X+ 0b11001 CONSTANT Y+ 0b10001 CONSTANT Z+
0b11110 CONSTANT -X 0b11010 CONSTANT -Y 0b10010 CONSTANT -Z
: _ldst ( Rd XYZ op ) SWAP DUP 0x10 AND 8 LSHIFT SWAP 0xf AND
OR OR ( Rd op' ) SWAP _Rdp A,, ;
: LD, 0x8000 _ldst ; : ST, SWAP 0x8200 _ldst ;

11
blk/671 Normal file
View File

@ -0,0 +1,11 @@
( L1 LBL! .. L1 ' RJMP LBL, )
: LBL! ( l -- ) PC SWAP ! ;
: LBL, ( l op -- ) SWAP @ 1- SWAP EXECUTE A,, ;
( L1 FLBL, .. L1 ' RJMP FLBL! )
: FLBL, ( l -- ) LBL! 0 A,, ;
: FLBL! ( l opw -- )
( warning: l is a PC offset, not a mem addr! )
SWAP @ 2 * ORG @ + PC 1- H@ ( opw addr tgt hbkp )
ROT HERE ! ( opw tgt hbkp ) SWAP ROT EXECUTE H@ ! ( hbkp )
HERE ! ;

View File

@ -40,6 +40,8 @@ Z: pointer to the next scan code to push to the 595 )
0x35 CONSTANT MCUCR 0x35 CONSTANT MCUCR
0x33 CONSTANT TCCR0B 0x33 CONSTANT TCCR0B
0x3b CONSTANT GIMSK 0x3b CONSTANT GIMSK
0x38 CONSTANT TIFR
0x32 CONSTANT TCNT0
0x16 CONSTANT PINB 0x16 CONSTANT PINB
0x17 CONSTANT DDRB 0x17 CONSTANT DDRB
0x18 CONSTANT PORTB 0x18 CONSTANT PORTB
@ -48,7 +50,9 @@ Z: pointer to the next scan code to push to the 595 )
3 CONSTANT CP 3 CONSTANT CP
0 CONSTANT LQ 0 CONSTANT LQ
4 CONSTANT LR 4 CONSTANT LR
0x100-100 CONSTANT TIMER_INITVAL 0x100 100 - CONSTANT TIMER_INITVAL
( We need a lot of labels in this program... )
VARIABLE L5 VARIABLE L6 VARIABLE L7 VARIABLE L8
H@ ORG ! H@ ORG !
L1 FLBL, ( main ) L1 FLBL, ( main )
@ -56,13 +60,13 @@ L2 FLBL, ( hdlINT0 )
( Read DATA and set GPIOR0/0 if high. Then, set flag T. ( Read DATA and set GPIOR0/0 if high. Then, set flag T.
no SREG fiddling because no SREG-modifying instruction ) no SREG fiddling because no SREG-modifying instruction )
RJMPOP L2 FLBL! ( hdlINT0 ) L2 ' RJMP FLBL! ( hdlINT0 )
PINB DATA SBIC, PINB DATA SBIC,
GPIOR0 0 SBI, GPIOR0 0 SBI,
SET, SET,
RETI, RETI,
RJMPOP L1 FLBL! ( main ) L1 ' RJMP FLBL! ( main )
16 RAMEND 0xff AND LDI, 16 RAMEND 0xff AND LDI,
SPL 16 OUT, SPL 16 OUT,
16 RAMEND 8 RSHIFT LDI, 16 RAMEND 8 RSHIFT LDI,
@ -95,4 +99,138 @@ DDRB LR SBI,
SEI, SEI,
L1 LBL! ( loop ) L1 LBL! ( loop )
L2 FLBL, ( BRTS processbit. flag T set? we have a bit to
process )
28 ( YL ) 30 ( ZL ) CP, ( if YL == ZL, buf is empty )
L3 FLBL, ( BRNE sendTo164. YL != ZL? buf has data )
( nothing to do. Before looping, let's check if our
communication timer overflowed. )
16 TIFR IN,
16 1 ( TOV0 ) SBRC,
L4 FLBL, ( RJMP processbitReset, timer0 overflow? reset )
( Nothing to do for real. )
L1 ' RJMP LBL, ( loop )
( Process the data bit received in INT0 handler. )
L2 ' BRTS FLBL! ( processbit )
19 GPIOR0 IN, ( backup GPIOR0 before we reset T )
19 0x1 ANDI, ( only keep the first flag )
GPIOR0 0 CBI,
CLT, ( ready to receive another bit )
( We've received a bit. reset timer )
L2 FLBL, ( RCALL resetTimer )
( Which step are we at? )
18 TST,
L5 FLBL, ( BREQ processbits0 )
18 1 CPI,
L6 FLBL, ( BREQ processbits1 )
18 2 CPI,
L7 FLBL, ( BREQ processbits2 )
( step 3: stop bit )
18 CLR, ( happens in all cases )
( DATA has to be set )
19 TST, ( was DATA set? )
L1 ' BREQ LBL, ( loop, not set? error, don't push to buf )
( push r17 to the buffer )
Y+ 17 ST,
L8 FLBL, ( RCALL checkBoundsY )
L1 ' RJMP LBL,
L5 ' BREQ FLBL! ( processbits0 )
( step 0 - start bit )
( DATA has to be cleared )
19 TST, ( was DATA set? )
L1 ' BRNE LBL, ( loop. set? error. no need to do anything. keep
r18 as-is. )
( DATA is cleared. prepare r17 and r18 for step 1 )
18 INC,
17 0x80 LDI,
L1 ' RJMP LBL, ( loop )
L6 ' BREQ FLBL! ( processbits1 )
( step 1 - receive bit
We're about to rotate the carry flag into r17. Let's set it
first depending on whether DATA is set. )
CLC,
19 0 SBRC, ( skip if DATA is cleared )
SEC,
( Carry flag is set )
17 ROR,
( Good. now, are we finished rotating? If carry flag is set,
it means that we've rotated in 8 bits. )
L1 ' BRCC LBL, ( loop )
( We're finished, go to step 2 )
18 INC,
L1 ' RJMP LBL, ( loop )
L7 ' BREQ FLBL! ( processbits2 )
( step 2 - parity bit )
1 19 MOV,
19 17 MOV,
L5 FLBL, ( RCALL checkParity )
1 16 CP,
L6 FLBL, ( BRNE processBitError, r1 != r16? wrong parity )
18 INC,
L1 ' RJMP LBL, ( loop )
L6 ' BRNE FLBL! ( processBitError )
18 CLR,
19 0xfe LDI,
L6 FLBL, ( RCALL sendToPS2 )
L1 ' RJMP LBL, ( loop )
L4 ' RJMP FLBL! ( processbitReset )
18 CLR,
L4 FLBL, ( RCALL resetTimer )
L1 ' RJMP LBL, ( loop )
L3 ' BRNE FLBL! ( sendTo164 )
( Send the value of r20 to the '164 )
PINB LQ SBIS, ( LQ is set? we can send the next byte )
L1 ' RJMP LBL, ( loop, even if we have something in the
buffer, we can't: the SMS hasn't read our
previous buffer yet. )
( We disable any interrupt handling during this routine.
Whatever it is, it has no meaning to us at this point in time
and processing it might mess things up. )
CLI,
DDRB DATA SBI,
20 Z+ LD,
L3 FLBL, ( RCALL checkBoundsZ )
16 8 LDI,
L7 LBL! ( sendToPS2Loop )
PORTB DATA CBI,
20 7 SBRC, ( if leftmost bit isn't cleared, set DATA high )
PORTB DATA SBI,
( toggle CP )
PORTB CP CBI,
20 LSL,
PORTB CP SBI,
16 DEC,
L7 ' BRNE LBL, ( sendToPS2Loop, not zero yet? loop )
( release PS/2 )
DDRB DATA CBI,
SEI,
( Reset the latch to indicate that the next number is ready )
PORTB LR SBI,
PORTB LR CBI,
L1 ' RJMP LBL, ( loop )
L2 ' RCALL FLBL! L4 ' RCALL FLBL! L2 LBL! ( resetTimer )
16 TIMER_INITVAL LDI,
TCNT0 16 OUT,
16 0x02 ( TOV0 ) LDI,
TIFR 16 OUT,
RET,
L6 ' RCALL FLBL! ( sendToPS2 )
( Send the value of r19 to the PS/2 keyboard )
CLI,
( First, indicate our request to send by holding both Clock low
for 100us, then pull Data low lines low for 100us. )
PORTB CLK CBI,
DDRB CLK SBI,
L2 ' RCALL LBL, ( resetTimer )