canon cat emulator status: implemented the watchdog timer, it now crashes better

apparently the rom freaks out at the lack of a working duart

agony of a 68000 program, not an oil on canvas, 2025
why, hello funny bar, some stuff is actually working if i see this i suppose

after implementing the bare minimum of the duart (two registers) the thing stopped crashing and the video framebuffer is actually getting filled with the interface (raw framebuffer is inverted so it's dark mode here)

now i did implement part of the keyboard (it's needed else the thing enters test mode, which understandably freaks out) and it's supposed to simulate the key "f" being pressed but i don't see it so further messing is needed i guess

prettied up my video grabber debug and fixed the keyboard (also simulating one keypress)

next step would be to hook up sdl, which i'm still not motivated to do so that's a problem for tomorrow me

this is the first emulator i've written that actually is that far into working btw

thinking of getting the input from stdin and spitting the video through stdout to ffplay as an alternative to using sdl, that's how much i don't want to use it

always wondered why getting a computer to spit out video is a systematically miserable experience

well that's the annoying part done, thanks to the umac emulator for the simple code templates

also admire the 1:1 pixel ratio that the mame emulator can't do

now to implement the keyboard so that i can type the world-famous* "Enable Forth Language"

*debatable

so, the keyboard, there's no pretty way of doing it i fear, with the added bonus of that i want the letters on my keyboard to match what i type (stares at mame and qwerty people)

i decided on separating it in two cases: whether the key is a letter or not, which is a terrible idea in general but in this case it works due to the production cat being us-only (so "letters" is A-Z and nothing else)

so here's all of those implemented (need to fix the timer to be time-based)

did implement most of the keyboard, unfortunately the "Enable Forth Language" feature half-crashes the emulator (the watchdog doesn't trigger)

(the Leap (R) and other features seem to work though)

i strongly suspect that it's due to the fact that enabling that should make the cat beep, which in the hardware means that it toggles back and forth a pin on the duart (yep it's barabaric, this machine is the most barbaric design i've seen yet)

found a way to enable the forth feature: you can replace the beep with a visual cue in the setup menu (also change the keyboard layout, but it's not ideal as the remapping is funky so my hack remains (may add a way to bypass it))

dunno anything about forth other than "it's the open firmware thing"

so the missing features from now would be the beep thing, the serial port and modem, the printer and floppy drive (also proper video sync)

the i/o ports are implemented as reading and writing to a specific address so all i'd have to do would be to forward that to a file if anything

the floppy drive will be hypercalled to death because that's the only sane way to do that that's not miserable

note to self since it's already breath of fire o'clock: when enabling forth with the beeper the four following things happen before the "crash":

unimplemented write 81001b = 04
unimplemented write 81000d = 00
unimplemented write 81000f = 02
unimplemented read 81001d

did a bit of housekeeping with the ~400 lines codebase of the emulator

did bite at the poor performance, it's now plently fast and responsive, need to test on a powerpc potato for endianness issues but i'm confident it'll run well there

implemented time accuracy* using both sdl functions and posix, selectable at compile time

*as best as possible: sdl is millisecond-based and the cat requires half-millisecond precision for surface-level accuracy, hence the posix implementation (also i want the thing to be sdl-independant for crime reasons)

still haven't found the issue for the beep thing crashing stuff

yeah it's fixed now, i'm still terrible at copying numbers

also the cat has a weird use of the duart interrupt system, where it'll ignore the actual interrupt if it's not from the timer and handle the other possible interrupts by reading periodically the interrupt status register

so at this point my canon cat emulator has feature-parity with the mame one while being way simpler

dunno when and how i'll give it a release yet, usually i do so when it's finished but here it may take a long time if i try to tackle the floppy drive emulation

also if anynyan has a SDL2 C build environment for windows xp or earlier i'd be interested

else i could try using the opengl 1 stack that's on windows since nt 3.51/95, need to find the program i made once using it (also fight old c compiler likely)

my codebase should be portable enough but the end machine still need to be able to emulate a whole 68000 at 4.9something MHz

trying to implement the printer made me look at the forth source code for the cat firmware

i have regrets, that thing is utterly unreadable

ohh it's waiting for the busy signal on IP4 on the <redacted> duart (i think)

they really exploitied that chip functionalities as much as they could

for some reason the "bidirectional mode" doesn't seem to do anything

i mean i won't complain that i don't have something to implement but still

at this point it's good enough to release but i'd need to make a script that would combine the four main roms into a single file because that's what my emulator takes

or i could put my own romset on the archive

forgor to implement the video blanking and invert

they had dark mode in 1987 i guess

dunno if select() or poll() is a thing on old windows compiler so i'll put the serial i/o in a define thingie

(edit: didn't catch that these work on file descriptors so it's unixy)

implementing the serial port, running into the problem that with a fifo the (canon) cat receives its own data if there isn't something faster to receive it instead

so it works with the cat command but not with another (canon) cat emulator

the sane solution is to allow for two files, one for read and one for writes

and it almost works except that fflush doesn't seem to do what it says on the tin :/

i have achieved cat-to-cat communication

the secret arcane was setvbuf() with the _IONBF flag

i don't intend to support the modem port since it's the exact same thing feature-wise but more annoying

only remaining thing to do now would be the floppy drive but since the serial thing is unix-only i'd like to see if i can add virtual tty support

a dumb optimisation i made: if no write to video memory has happened, don't update the screen

this does significantly reduces the cpu usage since the canon cat is only blinking the cursor around once a second at idle

a thing i tried is to backup the system ram and see if the canon cat can get back up that way

this lead me to a dive in the forth source code with the answer: maybe, if i also copy the cpu registers and trigger an nmi on reload (the nmi being wired to the watchdog timeout, and the source code calling this "warm boot")

actually i don't need to back up the registers, i just needed to adjust the threshold for the watchdog who was slightly too low

so now i have effectively a way to save up the system ram, which is the normal usecase for the floppy*

it also works the same way of directly showing the framebuffer upon startup, which is the feature that made me know this machine in the first place

also has the advantage of that it would be able to back up the emulator with moar ram, the floppy can only save 256K

*the other only usecase afaik is compiling the source code for the rom, but how to do that is very very "some assembly required"
@evv42 i'd guess it can be built in MSYS/Mingw32, right?
i don't have it around anymore
@wyatt probably, but i never got that to work
@evv42 i think i've done it, probably need an older sdl2 version