gigatron/rom/Core/Reset_v5.gcl
2025-01-28 19:17:01 +03:00

302 lines
10 KiB
Plaintext

{-----------------------------------------------------------------------+
| |
| Reset Gigatron (pseudo) hardware |
| |
+-----------------------------------------------------------------------}
gcl0x
{ No need for romType check because Reset.gcl gets hard-compiled in }
$1f8 CtrlBits=
{ CheckMemory }
[def
push
\memSize, 1- 255& 1+ i= {Number of pages as counted at boot}
{
Check for expander and 128K expanded memory
XXX We still need 100% reliable expander detection. Some notes:
1. The expander completely blocks the RAM write of ctrl()
2. An unexpanded system writes an uncontrolled Z-value in memory
-- We therefore may need to hook a 2.2K to BUS7 for writing
a controlled bit value. That can give reliable detection.
-- We could maybe also do a read back for positive detection
-- SendOnesToCard writes all over memory if there's no card.
3. gtemu.c writes arbitrary S.undef values that change slowly
XXX Moreover, it would be good if we can detect an interrupted
sector read and flush it
}
\SYS_ExpanderControl_v4_40 {SYS function}
_sysFn=
$aa $7c. {I/O expander detection}
$7c 40!! { Expanded: Disable SPI, set MOSI low, bank 1}
{ Unexpanded: Store undefined value in [$7c]}
$7c, $aa^ [if<>0 {Note: doesn't work if undefined value was $aa!}
0 CtrlBits. {No expander board detected}
else
$8024 q= {sysArgs0 + 32K}
$bc 40!! {Switch to bank 2}
q, 255^ q. {Invert value from memory}
_sysArgs0= {Copy result in sysArgs}
255^ q. {Invert memory value again}
_sysArgs0^ {Compare with inverted copy}
[if<>0 {If different then we have an A16 and 128K}
$31 Char= PrintChar! {'1'}
112 i=] {28*4 to give '28' below}
$807c 40!! {Set MOSI high, bank 1}
]
{ Convert memory page count to K in two decimals }
$2f2f Char= i {Two ASCII counters, both starting at '0'-1}
[do <Char++ 40- if>=0loop] 40+{Count number of 10K chunks}
[do >Char++ 4- if>=0loop] {Count number of 1K chunks}
PrintChar!
>Char, Char= PrintChar!
pop ret
] CheckMemory=
{ PrintS }
[def
{
Print ASCII string to screen
}
push
Text=
[do
Text, if<>0
Char=
10^ [if<>0 {Check for CR}
PrintChar!
else
2 <Pos. >Pos, 8+ >Pos. {Move one text line down, indented}
]
<Text++
loop]
pop ret
] PrintS=
{ PrintChar }
[def
{
Draw ASCII character on screen using the 5x8 pixel built-in font
}
<Char, 82- {Map ASCII code to offset in font table}
[if<0 50+ i= \font32up {First page for ASCII 32..81}
else i= \font82up] j= {Second page is ASCII 82..127}
i 2<< i+ {Multiply by 5}
j+ j= {Add page address to reach bitmap data}
\SYS_VDrawBits_134 _sysFn= {Prepare SYS call}
$3f20 \sysArgs0: {Blue/White}
Pos \sysArgs4: {Position of character}
6+ Pos= {Advance position by 6 pixels for next call}
5 [do i= {Loop to draw 5 vertical slices of 8 pixels}
j 0?? \sysArgs2. {Get byte from ROM using `LUP 0' instruction}
134!! {Invoke SYS function to draw 8 vertical pixels}
<j++ <\sysArgs4++ {Advance to next slice in ROM and on screen}
i 1- if>0loop] {Looping}
ret
] PrintChar=
{-----------------------------------------------------------------------+
|} >\vLR++ ret { RAM page 3 |
+-----------------------------------------------------------------------}
*=$0300
{ SetupChannel }
[def
{
Setup a note on one channel
High byte is channel, low byte is note (should be even)
Reset the oscillators and channel variables
}
i= 255| 255^ $fa| p= {Pointer to channel struct}
<i, i= {Extract note}
0 p. <p++ {.wavA}
3 p. <p++ {.wavX, 3=Sawtooth}
\notesTable i+ 0?? p. <p++ {.keyL}
\notesTable i+ 1?? p. <p++ {.keyH}
p. <p++ {.oscL}
p. {.oscH}
ret
] SetupChannel=
{ CheckCard }
[def
{ Try putting card in SPI mode and get a positive response }
push
16 [do
j=
{ Reset the SD Memory Card and put in SPI mode }
{
| """To communicate with the SD card, your program has to place the SD
| card into the SPI mode. To do this, set the MOSI and CS lines to
| logic value 1 and toggle SD CLK for at least 74 cycles."""
}
10 [do i= {Lets do 10 bytes for 80 cycles}
SendOnesToCard! {Keep MOSI line high by only sending ones}
i 1- if>0loop]
{
| """After the 74 cycles (or more) have occurred, your program
| should set the CS line to 0 and send the command CMD0:
| 01.000000 00000000 00000000 00000000 00000000 1001010.1
| This is the reset command, which puts the SD card into the SPI
| mode if executed when the CS line is low."""
}
{ EnableCard }
\SYS_ExpanderControl_v4_40 {SYS function}
_sysFn= $8078 40!! {Enable SPI0, keep MOSI high, bank 1}
{ Setup command bytes }
_Command=$81
[def #$ff #$ff {Start with two dummy bytes}
#$40 #0 #0 #0 #0 #$95] {CMD0: GO_IDLE_STATE}
p= \Command q=
8 [do i= {Copy command bytes to exchange buffer}
p, <p++ {Fetch byte and advance read pointer}
q. <q++ {Store byte and advance write pointer}
i 1- if>0loop] {Looping}
{ Send to SPI0 device }
\Command _sysArgs0= {Begin}
8+ _sysArgs2= {End and overwrite exchange buffer}
\SYS_SpiExchangeBytes_v4_134{SYS function}
_sysFn= 134!!
{
| """To receive this message, your program should continuously toggle
| the SD CLK signal and observe the MISO line for data, while keeping
| the MOSI line high and the CS line low. Your program can detect the
| message, because every message begins with a 0 bit, and when the
| SD card sends no data it keeps the MISO line high."""
}
{ WaitForCardReply }
16 [do i= {Poll for at least 8 reply bytes}
SendOnesToCard! {Keep MOSI line high by only sending ones}
128& {Note: communication is byte-aligned}
if<>0 {Break out when valid message detected}
i 1- if>0loop] {Or when loop counter exhausted}
{
| """Note that the response to each command is sent by the card a few
| SD CLK cycles later. If the expected response is not received within
| 16 clock cycles after sending the reset command, the reset command
| has to be sent again."""
}
{ DisableCard }
\SYS_ExpanderControl_v4_40 {SYS function}
_sysFn= $807c 40!! {Disable SPI, keep MOSI high, bank 1}
\sysArgs6, if<>0 {Break on zeroes from pull-down R1}
1^ [if=0 {Only 1 means success}
\Boot _sysArgs0= {Load Boot from ROM and execute}
$200 _vLR=
\SYS_Exec_88 _sysFn= 88!!]
j 1- if>0loop] {Retry}
pop ret
] CheckCard=
{ SendOnesToCard }
[def
255 \sysArgs6. {Place byte in exchange buffer}
\sysArgs6 _sysArgs0= {Begin}
1+ _sysArgs2= {End}
\SYS_SpiExchangeBytes_v4_134 {SYS function}
_sysFn= 134!! {Exchanges a single byte}
\sysArgs6, {Reply byte}
ret
] SendOnesToCard=
{-----------------------------------------------------------------------+
|}>\vLR++ ret{ RAM page 4 |
+-----------------------------------------------------------------------}
*=$0400
{ Resetting waveform tables after video/audio/vCPU have started }
\SYS_ResetWaveforms_v4_50 \sysFn: 0 50!!
\SYS_ShuffleNoise_v4_46 \sysFn: 0 46!! 46!! 46!! 46!!
{ Setup a G-major chord with 4 channels, but don't play it yet }
$158 {1: G-3} SetupChannel!
$270 {2: G-4} SetupChannel!
$378 {3: B-4} SetupChannel!
$47e {4: D-5} SetupChannel!
{ Setup video }
[
{ Setup video indirection table }
$100 p= {videoTable}
$800 q= {frame}
[do
>q, p. <p++ { Y[i] = 8..127}
0 p. <p++ {dX[i] = 0}
>q++ q if>0loop]
{ Clear screen }
\SYS_SetMemory_v2_54 _sysFn= {!!! Not in ROM v1 !!!}
32 \sysArgs1. {Color blue}
$800 [do
p= _sysArgs2= {Destination}
160 \sysArgs0. {Count}
54!! {SYS call}
$100 p+ if>0loop]
]
{ Restart blinkenlights }
\ledState_v2, 128& {Check if sequencer still running}
[if=0 \ledState_v2. \ledTimer.] {For continuity only restart when paused}
9 \ledTempo. {6.0 Hz ( = 60/(9+1)), was 5.5 Hz}
{
Print startup message
+--------------------------+
| *** Gigatron ??K *** |
| TTL microcomputer ROM vX |
+--------------------------+
| *** Gigatron 128K *** | <-- TODO Try 1 char less indent for 128K...
| TTL microcomputer ROM vX |
}
$814 Pos=
[def `***`Gigatron` #0] PrintS!
CheckMemory!
[def `K`***` #10
``TTL`microcomputer
``ROM`v5a #0] {ROM`vN for versioned release ROMs}
PrintS!
{ Change into default video mode }
\SYS_SetMode_v2_80 _sysFn= {!!! Not in ROM v1 !!!}
1 80!! {Mode 1 -> "ABC-"}
{ Try booting from memory card }
CtrlBits, [if<>0 CheckCard!]
{ Load and start ROM program }
\Main _sysArgs0= $200 _vLR= \SYS_Exec_88 _sysFn= 88!!
{-----------------------------------------------------------------------+
| |
+-----------------------------------------------------------------------}