GRiD Compass
// call from
// 0x216 (sub_146)
// 0x26a (sub_146)
// unknown parameter in accumulator
// unknown bank for R5. maybe bank0
uint8_t _28A_sub_translate_scan_code(uint8_t data) {
uint8_t a, R5;
R5 = 0xFC & (data << 2); // looze bits 7,6
a = (readRAM(0x29) >> 5) & 0x03; // 3 flags to bits 2,1,0
a = a | R5; // data on bits 7,6,5,4,3, flags on bits 3,2,1
// TEST0 pin looks like ignored
// bit0 on data ORs with PORT1 bit1
R5 = keyMatrix[a]; // bits 1,0 for modifier keys
if (bitRead(readRAM(0x29), bit7) != 0 ) { // if PORT1 bit0 set
R5 = 0x9F & R5 // clear/ignore bits 6,5
}
return R5;
}
// call from
// 0x026 (timer irq). bank1 for R5. accumulator = 0xFF
// 0x050 (main loop). bank1 for R5. accumulator = 0xFD
// 0x21e (sub_146). bank0 for R5???
// 0x274 (sub_146). bank0 for R5???
// unknown parameter in accumulator
// unknown bank for R5.
void _2A7_sub(uint8_t accumulator) {
// if bit0 in accumulator clear, activate NMI and return
if (bitRead(a, bit0) == 0) {
bitSet(PORT2, pin6); // activate NMI
return;
}
// if output buffer empty
// send a to CPU
// set bus status flags from R5
// activate interrupt
if ( !bitRead(busStatus, OBF)) {
bitClear(PORT2, pin3); // clear CPU IRQ pin
busOut = a; // send accumulator to CPU
busStatus = R5 & 0xF0; // set extra flags on bus status from R5
bitSet(PORT2, pin3); // activate CPU IRQ pin
return;
}
// otherwise:
RAM[0x27] = RAM[0x28];
if (RAM[0x28] == 0) {
RAM[0x28] = R5;
}
}
// could be bug
// GRiD programmer wanted to clear 12 byte buffer (3 byte struct 4 times)
// 0x14 - too much for buffer. will erase data in RAM[0x39]
// R4 must be 0xC
// no increment in R0 to advance RAM address
// ASM code
//PC:08E mov r4,014h ; bank 0 R4 = 0x14 (counter 0x14 times)
//PC:090 mov r0,02Bh ; bank 0 R0 = 0x2B
// .label_092:
//PC:092 mov @r0, 000h ; clear RAM 0x2B = 0
//PC:094 djnz r4, .label_092 ; repeat 0x14 times
//for (R4 = 0x14; R4 > 0; R4--) {
// writeRAM(0x00, 0x2B);
//}
// I'll do it correctly!
for (uint8_t i = 0x2B; i < 0x38; i++) {
writeRAM(0x00, i);
}
uint8_t sendData(uint8_t data, uint8_t flags) {
if ( data == 0xFE ) {
bitSet(PORT2, pinNMI);
return data;
}
blablabla
CPU to KBC protocol:
Address A0 clear - data
Address A0 set - command byte
Commands:
bit 7 clear: change master states (See RAM[0x1F] aga R7 bank 1)
* bit 0 - disable/enable keyboard scanning
* bit 1 - WDT1 related
* bit 2 - WDT0 related
* bit 3 - related (long routine). repeat last key? Uset in CpCatchRepeat CCPROM
* bit 4 - state for pinPAL (DMA)
* bit 5 - not used
* bit 6 - not used if bit 7 - clear
bit 7 set, bit 6 clear: data will follow on data port
* bits 0-2 (0,1,2,3) - write into one of config parameter registers (located in RAM 0x20-0x23)
* 0 - related to WDT0, Not used in CCPROM for 1101.
* 1 - key repeat rate/delay between key press
* 2 - key repeat rate/delay between key press
* 3 - related to WDT1. Used in CCPROM code to set WDT1 timeout
KBC to CPU protocol:
* Will rise interrupt when KBC want send data to CPU.
* unknown parameters for bits 4-7 in bus status register
* 0xFF - WDT0 timeout occured
* 0xFE - mentioned in CCPROM. Not found in KBC code
* 0xFD - WDT1 timeout occured
* other - key scan code. status bits 5-7 probably provide modifier keys state
* can send remainig data from key buffer if they exist. Check/send on timer IRQ.
Mechanism not know yet.
ccos utilsand show on presentations research process, he mentioned, that root directory entry is hardcoded to sector 0x121 (289), but... it nor works with bubble image. For bubble image file system structures are the same, but hardcoded root directory entry sector is on 0x3FE (1022) and sector size is 256 bytes on bubble, while on floppy and hdd (GRiB) sector size is 512.
[cpu] exec: Addr: 2000:0006, opcode: B8
[cpu] regs: AX: 0000, BX: 01CA, CX: 0000, DX: 0040
[cpu] regs: SI: 0700, DI: 2580, BP: 0134, SP: 012C
[cpu] regs: CS: 2000, DS: 02CA, ES: 0040, SS: 0298
02CA0: 06 00 00 20 08 00 3C FE 3E 01 98 02 00 01 FC 00
02CB0: 00 06 01 FD 03 FE 03 01 00 00 33 38 34 4B 2D 42
02CC0: 79 74 65 20 42 75 62 62 6C 65 20 20 47 52 69 44
02CD0: 20 50 4E 20 31 30 30 30 30 39 40 00 00 18 01 00
02CE0: CA 01 7E FE 00 00 00 07 00 20 09 00 00 00 00 01
02CF0: 00 00 FF 00 00 00 00 2A 00 00 00 00 00 00 00 00
02D00: 00 00 C4 02 D1 02 BE 02 FF FF 00 00 5B 5A 00 00
02D10: 00 00 D0 02 C8 02 BE 02 00 00 00 00 5B 5A 00 00
[cpu] exec: Addr: 2001:02FD, opcode: 9A
[cpu] regs: AX: 004B, BX: 0058, CX: 00FC, DX: 0000
[cpu] regs: SI: 02AB, DI: 0000, BP: 0E6F, SP: 0E6B
[cpu] regs: CS: 2001, DS: 2080, ES: 2080, SS: 2080
20800: 00 00 28 01 98 02 FF FF 7E FE 02 05 00 00 00 00
20810: B1 0A 80 20 3E 01 98 02 FF FF FF FF FF FF FF FF
20820: FF FF 00 01 FC 00 00 06 01 FD 03 FE 03 01 00 00
20830: 33 38 34 4B 2D 42 79 74 65 20 42 75 62 62 6C 65
20840: 20 20 47 52 69 44 20 50 4E 20 31 30 30 30 30 39
20850: 40 00 00 18 01 00 42 75 B1 01 00 00 0A 00 00 00
20860: B1 01 00 00 11 50 72 6F 67 72 61 6D 73 7E 73 75
20870: 62 6A 65 63 74 7E 00 00 00 00 00 00 00 00 00 00
ccos utlisand try to add support for bubble image.
#define bitRead(value, bit) (((value) >> (bit)) & 0x01)// Code and Shift keys to bits 1,0
uint8_t label_28A(uint8_t data) {
uint8_t tmp1, tmp2;
// key matrix result to bits 7,6,5,4,3,2
tmp2 = (data << 2) & 0xFC;
tmp1 = RAM[0x29] >> 5;// check for Ctrl key pressed
tmp1 = (tmp1 & 0x03) | tmp2;
tmp2 = page3Array[tmp1]; // get code from lookup table
if ( bitRead(RAM[0x29], 7) != 0 ) {
tmp2 &= 0x9F; // ctrl key pressed, do masking
}
return tmp2;
}
tmp1and
tmp2
bitRead, use meaningful variable names, and streamline the code for better readability. Here's the refactored version of the function:// Define a macro for reading a specific bit position
#define BIT_READ(value, bit) (((value) >> (bit)) & 0x01)
uint8_t decodeKeyMatrix(uint8_t data) {
uint8_t modifiedData, ctrlMaskedData;
uint8_t keyMatrixResult = (data << 2) & 0xFC; // Left shift and mask for key matrix result to bits 7,6,5,4,3,2
uint8_t codeShiftKeys = (RAM[0x29] >> 5) & 0x03; // Right shift and mask for Code and Shift keys to bits 1,0
// Combine key matrix result with code and shift keys
modifiedData = codeShiftKeys | keyMatrixResult;
// Retrieve the code from the lookup table using modified data
ctrlMaskedData = page3Array[modifiedData];
// Check if the Ctrl key is pressed
if (BIT_READ(RAM[0x29], 7)) {
// Ctrl key is pressed, apply masking
ctrlMaskedData &= 0x9F;
}
return ctrlMaskedData;
}
bitRead macro is properly named as BIT_READ following the convention for macro names.tmp1 and tmp2 are renamed to codeShiftKeys and modifiedData, respectively, to describe their roles.BIT_READ only once, and that RAM and page3Array are defined and accessible within the scope of this function. Also, ensure that the code conforms to any specific coding standards or constraints you may have in your project.
grid_compass_1129_bios.bin
0000 3F00: EA 43 10 01 FC EA 42 22 01 FC EA 62 00 11 FF EA .C....B" ...b....
0000 3F10: CD 01 98 02 EA 0C 00 C9 FE EA 3C 20 01 FC EA 5B ........ ..< ...[
0000 3F20: 20 01 FC EA AC 20 01 FC EA B6 1F 01 FC EA D6 1F .... .. ........
0000 3F30: 01 FC EA F4 1F 01 FC EA 22 20 01 FC EA 96 21 01 ........ " ....!.
0000 3F40: FC EA F5 21 01 FC EA C0 21 01 FC EA 50 1B 01 FC ...!.... !...P...
0000 3F50: EA 7C 1B 01 FC EA A6 1B 01 FC EA C7 1B 01 FC EA .|...... ........
0000 3F60: 03 1D 01 FC EA 39 1D 01 FC EA 6A 1D 01 FC EA 8B .....9.. ..j.....
0000 3F70: 1D 01 FC EA CC 1D 01 FC EA 51 18 01 FC EA 8F 18 ........ .Q......
0000 3F80: 01 FC EA DA 18 01 FC EA AE 19 01 FC EA E1 19 01 ........ ........
0000 3F90: FC EA 30 1A 01 FC EA 72 1A 01 FC EA 22 0F 01 FC ..0....r ...."...
0000 3FA0: EA ED 10 01 FC EA 3E 11 01 FC EA D9 11 01 FC EA ......>. ........
0000 3FB0: 74 12 01 FC EA 87 12 01 FC EA 5C 13 01 FC EA B9 t....... ..\.....
0000 3FC0: 13 01 FC EA 50 14 01 FC EA 90 14 01 FC EA D9 14 ....P... ........
0000 3FD0: 01 FC EA 14 15 01 FC EA 44 1E 01 FC EA 58 1E 01 ........ D....X..
0000 3FE0: FC EA 90 1E 01 FC EA C0 1E 01 FC EA F5 1E 01 FC ........ ........
0000 3FF0: EA A0 23 01 FC 40 00 40 01 F0 00 64 00 01 00 00 ..#..@.@ ...d....
0000 4000:
AM27C64_DIP28_1129_merged.BIN
0000 3F00: EA 42 10 00 FC EA 42 22 01 7C EA 62 00 10 FF EA .B....B" .|.b....
0000 3F10: CD 01 98 02 EA 0C 00 49 FE 6A 3C 20 01 7C 6A 5A .......I .j< .|jZ
0000 3F20: 20 01 FC EA AC 20 01 FC EA B6 1E 01 FC EA D6 1E .... .. ........
0000 3F30: 01 FC EA F4 1F 01 FC 6A 22 20 01 FC EA 96 21 01 .......j " ....!.
0000 3F40: FC EA F4 21 01 FC EA C0 20 01 7C EA 50 1B 00 FC ...!.... .|.P...
0000 3F50: EA 7C 1B 01 FC 6A A6 1B 01 7C 6A 47 1B 01 FC 6A .|...j.. .|jG...j
0000 3F60: 02 1C 01 FC EA 39 1D 00 FC EA 6A 1C 00 FC 6A 8B .....9.. ..j...j.
0000 3F70: 1D 01 FC EA 4C 1D 01 FC 6A 51 18 01 7C 6A 0F 18 ....L... jQ..|j..
0000 3F80: 00 FC EA DA 18 00 7C EA AE 19 01 FC EA E1 18 01 ......|. ........
0000 3F90: FC 6A 30 1A 01 7C 6A 72 1A 01 7C 6A 22 0F 01 7C .j0..|jr ..|j"..|
0000 3FA0: EA EC 10 00 FC EA 3E 10 00 FC EA 58 10 00 FC EA ......>. ...X....
0000 3FB0: 74 12 01 7C EA 07 12 00 FC 6A 5C 13 01 7C 6A 38 t..|.... .j\..|j8
0000 3FC0: 12 00 FC EA 50 14 00 FC 68 90 14 01 7C EA D8 14 ....P... h...|...
0000 3FD0: 01 7C 6A 14 15 01 FC 6A 44 1E 01 7C 6A 58 1E 01 .|j....j D..|jX..
0000 3FE0: FC EA 90 1E 01 FC EA 40 1E 01 FC EA F4 1E 01 7C .......@ .......|
0000 3FF0: EA A0 23 01 FC 40 00 40 01 70 00 64 00 01 00 00 ..#..@.@ .p.d....
0000 4000:
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
βArrow keys move F find RET next difference ESC quit T move top β
βC ASCII/EBCDIC E edit file G goto position Q quit B move bottom β
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
grid_compass_1129_bios.bin
0000 21F0: D0 8A 04 83 C6 02 24 F0 0A C2 26 88 05 47 E2 E2 ......$. ..&..G..
0000 2200: 5D 1F CA 04 00 1E 55 8B EC B8 F4 DF 8E D8 C6 06 ].....U. ........
0000 2210: 1D 00 01 8A 5E 08 B7 00 2E 8A 9F 44 1F B9 88 13 ....^... ...D....
0000 2220: 8A 07 24 0F 3C 0F E1 F8 5D 1F CA 02 00 1E B8 EC ..$.<... ].......
0000 2230: DF 8E D8 C6 06 06 00 C0 C6 06 02 00 7F C6 06 06 ........ ........
0000 2240: 00 03 C6 06 06 00 00 B8 04 00 50 9A 22 20 01 FC ........ ..P." ..
0000 2250: 1F C3 B8 98 02 8E C0 BB AC 01 CB 2E 8E 1E 30 1F ........ ......0.
0000 2260: B8 30 00 A3 89 02 B8 6C FF A3 8B 02 B0 00 E8 F3 .0.....l ........
0000 2270: FC B8 FC DF 8E C0 26 A0 00 00 B0 18 A2 4C 02 E8 ......&. .....L..
0000 2280: E2 FC C7 06 48 02 05 19 B0 02 50 B8 01 FC 50 B8 ....H... ..P...P.
0000 2290: 23 23 50 9A F4 1F 01 FC B0 02 50 50 9A B6 1F 01 ##P..... ..PP....
0000 22A0: FC C7 06 40 02 8D 1F C7 06 42 02 01 FC C7 06 44 ...@.... .B.....D
0000 22B0: 02 8D 1F C7 06 46 02 01 FC C7 06 4A 02 00 00 C6 .....F.. ...J....
0000 22C0: 06 CD 01 EA C7 06 CE 01 11 00 EB 31 00 00 00 00 ........ ...1....
0000 22D0: 33 33 30 30 30 30 34 34 32 31 30 39 2D 2D 31 31 33000044 2109--11
0000 22E0: 37 37 20 3C 3C 2D 2D 20 70 70 61 61 72 72 74 74 77 <<-- ppaarrtt
0000 22F0: 20 6E 6E 75 75 6D 6D 62 62 65 65 72 72 C7 06 D0 nnuummb beerr...
AM27C64_DIP28_1129_merged.BIN
0000 21F0: D0 0A 04 03 46 02 24 70 0A 42 26 08 05 47 62 62 ....F.$p .B&..Gbb
0000 2200: 5C 1E CA 04 00 1E 54 0A 6C 38 F4 5E 8E 58 46 06 \.....T. l8.^.XF.
0000 2210: 1C 00 00 0A 5E 08 36 00 2E 0A 1F 44 1F 39 08 13 ....^.6. ...D.9..
0000 2220: 0A 06 24 0E 3C 0E E0 F8 5C 1E 4A 02 00 1E B8 6C ..$.<... \.J....l
0000 2230: DE 0E 58 C6 06 06 00 40 06 06 02 00 7E 46 06 06 ..X....@ ....~F..
0000 2240: 00 02 C6 06 06 00 00 B8 04 00 50 1A 22 20 00 7C ........ ..P." .|
0000 2250: 1E 42 B8 18 02 0E C0 3B 2C 01 4A 2E 0E 1E 30 1F .B.....; ,.J...0.
0000 2260: 38 30 00 22 88 02 B8 6C 7E 22 0A 02 30 00 E8 72 80."...l ~"..0..r
0000 2270: 7C 38 7C 5F 0E 40 26 20 00 00 30 18 22 4C 02 68 |8|_.@& ..0."L.h
0000 2280: E2 7C C6 06 48 02 04 18 30 02 50 38 00 7C 50 38 .|..H... 0.P8.|P8
0000 2290: 22 22 50 1A 74 1F 00 7C 30 02 50 50 1A 36 1F 01 ""P.t..| 0.PP.6..
0000 22A0: 7C 44 06 40 00 0C 1C 46 06 42 02 00 FC 46 06 44 |D.@...F .B...F.D
0000 22B0: 02 0C 1E 46 06 46 02 01 3C 47 06 4A 02 00 00 46 ...F.F.. <G.J...F
0000 22C0: 06 CC 00 EA C6 06 CE 00 10 00 6A 31 00 00 00 00 ........ ..j1....
0000 22D0: 32 33 30 30 30 30 34 34 32 31 30 39 2D 2D 31 31 23000044 2109--11
0000 22E0: 36 36 20 3C 3C 2C 2C 20 70 70 60 61 72 72 74 74 66 <<,, pp`arrtt
0000 22F0: 20 6E 6E 75 75 6D 6C 62 62 65 65 72 32 47 06 50 nnuumlb beer2G.P
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
βArrow keys move F find RET next difference ESC quit T move top β
βC ASCII/EBCDIC E edit file G goto position Q quit B move bottom β
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
B`nnnt bnnt: Rt.r`fd lddhtl drpnp