Close

20230216c -- File RAM Page Selection

A project log for ROM Disassembly - AlphaSmart Pro

Wherein I disassemble the ROM from a vintage typewriter-thing

ziggurat29ziggurat29 02/20/2023 at 22:010 Comments

Earlier I mentioned the discovery of the 'file partition table', but noted that there is not an indication of page number, and speculated that there must be some routine or table somewhere that provides that additional data.  I also speculated that it might be based on a switch-like code structure.  I was wrong on both accounts.

It turns out there is a little bit of cleverness in how a file number is translated to a RAM page, and it relies on the file number being human friendly and the file sizes being roughly a geometric progression.

The routine for mapping file no to RAM page number is here:

EC80             ; select in the relevant RAM page based on file number (byte_15D)
EC80             selectRAMpageForFile_EC80:
EC80 8D F7           bsr     selectRAMPage0_EC79 ; select 32 KiB RAM page 0
EC82 B6 01 5D        ldaa    byte_15D        ; current file number (1-8)
EC85 81 08           cmpa    #8
EC87 24 04           bcc     oobFileNo_EC8D  ; (file no is bonkers)
EC89 44              lsra                    ; (translate 1-8, to 0-3 with nifty math)
EC8A             loc_EC8A:
EC8A 8D D4           bsr     selectRAMPageA_EC60 ; select 32 KiB RAM page as per A (0-3)
EC8C 39              rts
EC8D             oobFileNo_EC8D:
EC8D 86 03           ldaa    #3              ; (saturate to page 3)
EC8F 20 F9           bra     loc_EC8A

So, RAM page 0 has one file, page 1 has two files, page 2 has two files, and page 3 has 3 files.  Because the file numbers are human friendly and 1-relative, the numbers 1-8 when shifted down map to the sequence: 0,1,1,2,2,3,3,3.  In a 'perfect' world this would mean that page 3 has 4 8 KiB 'files', but instead we have two ~ 12 KiB files and one residual ~ 8 KiB file and no 4th file.

So, pretty clever.  In modernity we tend to do less of cleverness of this sort because it is brittle.  What if the product design changed such that the various file sizes did not fit this convenient approximate progression?  Is it also not scalable; what if we want 16 files?  This design requires that file sizes ever diminish so as to preserve the logarithmic mapping, and to extend this design would imply going to a farcically small file size rather quickly. 

Discussions