Author Topic: 8X+[SE] - universal snacks  (Read 6217 times)

0 Members and 1 Guest are viewing this topic.

Offline the_mad_joob

  • LV6 Super Member (Next: 500)
  • ******
  • Posts: 342
  • Rating: +47/-0
    • View Profile
8X+[SE] - universal snacks
« on: June 28, 2019, 09:38:06 am »
INTRODUCTION

This is a pack of routines and various files i've built over the years.
I can't say i haven't been inspired by others, so some stuff expands|fixes existing work.
Optimisation is mostly towards speed, and system code is used as rarely as possible.
Each file includes deep documentation.



COMPATIBILITY

Except if specified, all TI-8X+ models (monochrome screen) are supported.
Same goes for official systems and boot codes.
Everything else should be considered unsupported.



DISCLAIMER

For each routine, you are expected to follow EVERYTHING that's in the "IN" section.
Also, when there's a "WARNING" section, it's to be taken seriously.
If something is unclear, feel free to ask there BEFORE using : https://www.omnimaga.org/asm-language/flash-snacks/



NOTE ABOUT "OUT" SECTIONS

? means a register is to be considered destroyed.

Unlisted registers are unchanged, except for :
pc,r : always destroyed
af',bc',de',hl' : unchanged if interrupts disabled beforehand | destroyed otherwise

When the f register is detailed, each bit can be :
0 : zero
1 : one
X : variable-known (see "flags")
? : variable-unknown (destroyed)



CONTENT & OVERVIEW

keyboard.inc : keyboard include file
ti83plus.inc : ultimate TI-83+|TI-83+SE|TI-84+|TI-84+SE include file

font_large_custom.png : preview of what's in font_large_custom.z80
font_large_system.png : system 6x8p character font preview (2.53+)

1_character_tokens.txt : token>character reference table for all valid 1-character-long tokens
READ.txt : this file
system_ram_structure.txt : system ram structure summary

arcpages.z80 : Identifies the reference pages of the archive.
battcheck.z80 : Checks batteries.
bootver.z80 : Identifies the boot code version.
cpirnc.z80 : Similar to cpir, but additionally halts if a bank edge is reached.
cpirz.z80 : Similar to cpir, but instead halts if the specified byte isn't found.
cpirznc.z80 : Similar to cpir, but instead halts if the specified byte isn't found, and additionally halts if a bank edge is reached.
flashlock.z80 : Locks the flash chip.
flashmanuf.z80 : Identifies the flash chip manufacturer.
flashunlock.z80 : Unlocks the flash chip.
font_large_custom.z80 : custom 6x8p character font matching ASCII|ISO-8859-1|CP-1252
guiselect.z80 : Provides interaction with a simple 6x8p-text-based option selection GUI, using a custom cursor.
intdefault.z80 : Sets all hardware interrupts to the default system configuration.
intdisable.z80 : Disables and acknowledges all hardware interrupts.
keybcheck.z80 : Checks if at least one key is pressed, and if it's [ON].
keybdebounce.z80 : Waits long enough for released keys to stop bouncing.
keybscan.z80 : Scans the whole keyboard, [ON] key excepted.
lcdcfg.z80 : common LCD configuration
lcddispbuf.z80 : Displays the content of a custom fullscreen buffer.
lcddispchr.z80 : Displays a 6x8p character, using a custom font.
lcddispstr.z80 : Displays a string of 6x8p characters, using a custom font.
lcddisptxt.z80 : Displays the content of a custom fullscreen text buffer, using a custom 6x8p character font.
lcdfill.z80 : Fills the screen with the same byte, mostly used to clear all pixels.
lcdsavebuf.z80 : Stores the display to a custom fullscreen buffer in RAM.
poweroff.z80 : Turns off the calculator, and waits for an [ON] key press.
prgmedit.z80 : Exits, opens the program editor for the specified program, and sets the cursor to the specified location.
r16strdec.z80 : Converts a 16-bit value to a decimal character string, and writes it to RAM.
r8strbin.z80 : Converts an 8-bit value to a binary character string, and writes it to RAM.
r8strdec.z80 : Converts an 8-bit value to a decimal character string, and writes it to RAM.
r8strhex.z80 : Converts an 8-bit value to a hexadecimal character string, and writes it to RAM.
ramlock.z80 : Sets RAM execution permission to the system default configuration.
ramsize.z80 : Identifies the physical RAM size.
ramunlock.z80 : Makes all RAM executable.
romlock.z80 : Sets ROM execution permission to the system default configuration.
romsize.z80 : Identifies the physical ROM size.
romunlock.z80 : Makes all ROM executable.
romwrite1.z80 : Writes a byte to ROM.
romwritex.z80 : Similar to ldir, but instead writes to ROM, and additionally halts if a bank edge is reached.
secterase.z80 : Erases a sector.
sectstate.z80 : Checks a sector for protection against write|erase operations.
strdelz.z80 : Replaces the potential leading zeros of the specified character string in RAM by spaces.
sysver.z80 : Identifies the system version.
usbinfo.z80 : Identifies if USB is available, and its revision type.
« Last Edit: August 18, 2021, 05:18:13 am by the_mad_joob »

Offline E37

  • LV6 Super Member (Next: 500)
  • ******
  • Posts: 316
  • Rating: +21/-0
  • Trial and error is the best teacher
    • View Profile
Re: [8X+] flash snacks
« Reply #1 on: June 28, 2019, 08:15:20 pm »
Those are pretty neat especially the last one! I wish I had an excuse to use them.
Why don't you include a faster version of the flash to ram bcall while you are at it? It should be pretty easy since all you have to do is swap the flash bank into $4000-$4FFF and ldir it to ram and swap the page when needed.
I'm still around... kind of.

Offline the_mad_joob

  • LV6 Super Member (Next: 500)
  • ******
  • Posts: 342
  • Rating: +47/-0
    • View Profile
Re: [8X+] flash snacks
« Reply #2 on: June 28, 2019, 09:01:46 pm »
Those are pretty neat especially the last one! I wish I had an excuse to use them.
Why don't you include a faster version of the flash to ram bcall while you are at it? It should be pretty easy since all you have to do is swap the flash bank into $4000-$4FFF and ldir it to ram and swap the page when needed.
Yeah, the day i coded the last one, i truly fell in love with conditionnal ret instructions, as a freakin' fast way to exit very low level loops.
About the routine you're talking about, it's not what i would exactly call flash-related, since you're writing to ram, so i'm not sure if it fits in this thread.
Also, i'm pretty sure plenty of routines like that can already be found.

Offline TIfanx1999

  • ಠ_ಠ ( ͡° ͜ʖ ͡°)
  • CoT Emeritus
  • LV13 Extreme Addict (Next: 9001)
  • *
  • Posts: 6173
  • Rating: +191/-9
    • View Profile
Re: [8X+] flash snacks
« Reply #3 on: June 29, 2019, 11:40:07 am »
Those are pretty neat especially the last one! I wish I had an excuse to use them.
^This. Nice work!

Offline Xeda112358

  • they/them
  • Moderator
  • LV12 Extreme Poster (Next: 5000)
  • ************
  • Posts: 4678
  • Rating: +718/-6
  • Calc-u-lator, do doo doo do do do.
    • View Profile
Re: [8X+] flash snacks
« Reply #4 on: June 29, 2019, 01:06:51 pm »
Thanks a bunch, I might think a way to use this! @E37 : there are some pretty decent existing flash-to-RAM routines.
A classic way to increment HL through RAM pages is to do something like:
Code: [Select]
    inc l
    call z,incHLmem1
...
...
incHLmem1:
  inc h
  ret po
  ld h,a
  in a,(6)
  inc a
  out (6),a
  ld a,h
  ld h,40h
  ret
That method averages between 14cc and 15cc and advances the page as needed. You need to initialize by swapping in the correct page, though.

Here is my take on a flash-to-RAM routine, though:
Code: [Select]
FlashToRAM:
;Inputs: Same as LDIR, but A is the page number.
;Outputs:
;    Same as LDIR, except A is the ending page.
;
;Speed:
;RAM: 21+21n
;ARC, but no boundary: 114+21n
;Arc, on two pages: 21n+269
;Arc, on three pages: 21n+355
  or a
  jp z,ReadRAM
  out (6),a
  add hl,bc
;  jr c,read_from_Arc_blocks   ;if you need this, you probably need a different routine. This implies that writing will eventually reach the 0x0000 to 0x3FFF range.
  jp p,read_from_ARC_noboundary
read_from_Arc_blocks:
;If we make it here, we know that we cross a page boundary (or in one case, we just reach it and need to return on the next page).
;We will read in blocks to avoid checking page boundaries
;To do so, we first read up to 0x8000 - HL bytes
  xor a
  sbc hl,bc
  sub l \ ld l,a
  ld a,$80 \ sbc a,h \ ld h,a
  ;now we will subtract BC-HL  -> BC
  ld a,c \ sub l \ ld c,a
  ld a,b \ sbc a,h \ ld b,a
  push bc
  ld b,h
  ld c,l
  xor a \ sub l \ ld l,a
  ld a,$80 \ sbc a,h \ ld h,a
  ;now we read the first block
block_loop:
  ldir
  ;now we increment the page and continue reading from $4000
  in a,(6)
  inc a
  out (6),a
  ld h,40h
  pop bc
  ;if BC<$4000, just LDIR the rest
  ld a,b
  sub h
  jr c,read_from_RAM
  ld b,a
  push bc
  ld b,h
  ld c,l
  jp block_loop
read_from_ARC_noboundary:
;  or a     ;already reset
  sbc hl,bc
read_from_RAM:
  ldir
  in a,(6)
  ld b,a
page_restore = $+1
  ld a,0
  out (6),a
  ld a,b
  ld b,c
  ret
ReadRAM:
  ldir
  ret
It needs to run in RAM and uses SMC.

Offline the_mad_joob

  • LV6 Super Member (Next: 500)
  • ******
  • Posts: 342
  • Rating: +47/-0
    • View Profile
Re: [8X+] [B&W] universal snacks
« Reply #5 on: August 01, 2019, 05:08:11 am »
August snacks just arrived !
Added 19 new routines.
I will probably add 2 more packs in the future, lcd & archive stuff.

Offline the_mad_joob

  • LV6 Super Member (Next: 500)
  • ******
  • Posts: 342
  • Rating: +47/-0
    • View Profile
Re: [8X+] [B&W] universal snacks
« Reply #6 on: August 13, 2019, 06:50:56 am »
CHANGES

> Continued to improve descriptions & comments.
> Added necessary warnings for noobs.
> Code change : keybscan (slightly faster, different outputs).
> LCD snack pack was added, including 11 routines, and a fully Notepad-compatible font.

EDIT

Slightly updated the following, which are now slightly faster :
lcddisp
lcddispstrb
lcdfill
lcdinv
lcdinvchr
lcdinvstr
lcdsave
« Last Edit: August 14, 2019, 02:40:38 pm by the_mad_joob »

Offline the_mad_joob

  • LV6 Super Member (Next: 500)
  • ******
  • Posts: 342
  • Rating: +47/-0
    • View Profile
Re: [8X+] [B&W] universal snacks
« Reply #7 on: August 23, 2019, 04:45:56 am »
UPDATE

> lcddispcur has been replaced by lcdinvcur, which performs a cursor inversion, rather than just a display.
> sectcheck is now able to detect soft protection.
> optimised : intdefaults,intdisable,lcdcfg,lcddisp,lcddispstrb,lcdfill,lcdinv,lcdsave,romwrite1,romwritex
> No more .txt files, each .z80 now has its full documentation inside.
> Merged variants of the same routine into a single .z80.
> Some routines have been renamed to better match what they do.

Offline the_mad_joob

  • LV6 Super Member (Next: 500)
  • ******
  • Posts: 342
  • Rating: +47/-0
    • View Profile
Re: [8X+] [B&W] universal snacks
« Reply #8 on: August 24, 2020, 05:03:34 am »
NEW

arcpagesa (memory\arcpages.z80)
arcpagesb (memory\arcpages.z80)
cleanexit (utility\cleanexit.z80)
cpirnc (memory\cpirnc.z80)
cpirz (memory\cpirz.z80)
cpirznc (memory\cpirznc.z80)

CHANGES

battchecka : now fully standalone
battcheckb : slightly faster
flashlocka : slightly faster
flashlockb : slightly faster
flashsize : now called romsizeb and now in romsize.z80
flashunlocka : slightly faster
flashunlockb : slightly faster and now using the stack instead of a custom RAM location for backup
font : $00>$1F and $7F now blank for accuracy purpose
keybscan : slightly faster and more consistent
romsize : now called romsizea
romwritex : slightly faster
sectcheck : now called secstate for accuracy purpose
secterase : slightly faster

Application variants now come first in each file.
Improved the documentation here & there.
Everything is in one zip now.
« Last Edit: August 27, 2020, 03:57:20 am by the_mad_joob »

Offline the_mad_joob

  • LV6 Super Member (Next: 500)
  • ******
  • Posts: 342
  • Rating: +47/-0
    • View Profile
Re: [8X+] universal snacks
« Reply #9 on: December 27, 2020, 04:53:09 pm »
CHANGED

LCD :
Inversion routines were removed (obsolete).
All others were updated to support most recent hardware (bit 7 of port $10 no longer polled).

specific :
battchecka : a bit closer to TI's original code
cleanexit : removed (obsolete)
cpirnc : now interrupt-friendly (af' no longer used)
cpirznc : now interrupt-friendly (af' no longer used)
keybscan : faster detection, also now foolproof and key repeat friendly
poweroff : not IM2-exclusive anymore

A few files|routines were renamed.
Continued to improve documentation here & there.

NEW

keybcheck
keybdebounce
prgmedita
prgmeditb

HAPPY 2021 IN ADVANCE =]

#####

CHANGED

No more subfolders.
font_large_custom.png (font.png before) : a few sprites improved
font_large_custom.txt (font.txt before) : a few sprites improved
lcddispchr : slightly faster at 6MHz
lcddispstr : slightly faster at 6MHz
prgmedita : now mathprint-compatible and with additional securities
prgmeditb : now mathprint-compatible and with additional securities

NEW

ti83plus.inc : ultimate TI-83+|TI-83+SE|TI-84+|TI-84+SE include file
font_large_system.png : large character system font preview
1_character_tokens.txt : token>character reference table for all valid 1 character long tokens
font_large_system.txt : information about large character system font

#####

CHANGED

ti83plus.inc : new information about 3 undocumented system flags (iy+49h)
prgmedita : slightly faster
prgmeditb : slightly faster

NEW

system_ram_structure.txt : system ram structure summary
« Last Edit: January 17, 2021, 02:37:53 am by the_mad_joob »

Offline the_mad_joob

  • LV6 Super Member (Next: 500)
  • ******
  • Posts: 342
  • Rating: +47/-0
    • View Profile
Re: [8X+] universal snacks
« Reply #10 on: February 07, 2021, 03:17:13 am »
NEW

guiselect.z80 : Provides interaction with a simple 6x8p-text-based option selection GUI, using a custom cursor.
strdelz.z80 : Replaces the leading zeros of the specified character string in RAM by spaces.
val16tostrd.z80 : Converts a 16-bit value to a decimal character string, and writes it to RAM.

CHANGED

lcdsavebuf : LCD RAM reading algorithm fixed

Continued to improve documentation.

#####

NEW

r8strbin.z80 : Converts an 8-bit value to a binary character string, and writes it to RAM.
r8strdec.z80 : Converts an 8-bit value to a decimal character string, and writes it to RAM.
r8strhex.z80 : Converts an 8-bit value to a hexadecimal character string, and writes it to RAM.

CHANGED

arcpagesa : faster and smaller
arcpagesb : faster and smaller
bootvera : more register-friendly
bootverb : more register-friendly
flashlocka : faster and smaller
flashlockb : faster and smaller
flashmanuf : faster and detects extended identification properly
flashunlocka : faster
flashunlockb : faster and more stack-friendly
guiselect : cursor more visible when moving
poweroff : faster
romwritex : smaller
sysvera : more register-friendly
sysverb : more register-friendly
val16tostrd : faster and now called r16strdec

Continued to improve documentation.

#####

CHANGED

flashunlocka : now working properly on OS 2.21 & 2.22
flashunlockb : now working properly on OS 2.21 & 2.22
romwrite1 : fixed an unlikely case of false positive failure
romwritex : fixed an unlikely case of false positive failure
secterase : fixed an unlikely case of false positive failure

Continued to improve the documentation.
« Last Edit: March 06, 2021, 08:36:31 pm by the_mad_joob »

Offline the_mad_joob

  • LV6 Super Member (Next: 500)
  • ******
  • Posts: 342
  • Rating: +47/-0
    • View Profile
Re: 8X+[SE] - universal snacks
« Reply #11 on: August 15, 2021, 12:55:30 pm »
NEW

App variants of the following are now available :

flashmanuf
romsize
romwrite1
romwritex
secterase
sectstate

They automatically handle the RAM code copy and execution, and only use the stack.

UPDATED

arcpages : faster and smaller
battcheck : prgm variant faster and smaller
cpirnc : smaller
flashunlock : non-destructive variant fixed
guiselect : disabled hardware interrupts now required
romwritex : faster and smaller

No longer using letter suffixes in variant names.
Continued to improve the documentation.

#####

UPDATED

The following now use a register pair for the temporary RAM location, rather than a fixed address :

battcheck - prgm variant
flashmanuf - app variant
flashunlock - non-destructive variant
romsize - foolproof app variant
sectstate - app variant

The following now use an equate for the temporary RAM location, rather than a fixed address :

romwrite1 - app variant
romwritex - app variant
secterase - app variant
« Last Edit: August 17, 2021, 04:02:43 pm by the_mad_joob »