Author Topic: [8X+] [B&W] universal snacks  (Read 905 times)

0 Members and 1 Guest are viewing this topic.

Offline the_mad_joob

  • LV6 Super Member (Next: 500)
  • ******
  • Posts: 302
  • Rating: +45/-0
    • View Profile
[8X+] [B&W] universal snacks
« on: June 28, 2019, 09:38:06 am »
Welcome.

All routines are compatible with all 8X+ B&W models.
Those are pretty low-level, so except for a few, no system code is used.
You guessed it, optimisation is clearly towards speed.
Each file includes deep documentation, please read everything before using.
Don't hesitate to ask if something is unclear.

Enjoy =]



flash.zip

flash\flashlock.z80
flash\flashmanuf.z80
flash\flashsize.z80
flash\flashunlock.z80
flash\romwrite1.z80
flash\romwritex.z80
flash\sectcheck.z80
flash\secterase.z80

lcd.zip

lcd\font.png
lcd\font.z80
lcd\lcdcfg.z80
lcd\lcddisp.z80
lcd\lcddispchr.z80
lcd\lcddispstr.z80
lcd\lcdfill.z80
lcd\lcdinv.z80
lcd\lcdinvchr.z80
lcd\lcdinvcur.z80
lcd\lcdinvstr.z80
lcd\lcdsave.z80

memory.zip

memory\ramlock.z80
memory\ramsize.z80
memory\ramunlock.z80
memory\romlock.z80
memory\romsize.z80
memory\romunlock.z80

utility.zip

utility\keyboard.inc
utility\battcheck.z80
utility\bootver.z80
utility\intdefaults.z80
utility\intdisable.z80
utility\keybscan.z80
utility\poweroff.z80
utility\sysver.z80
utility\usbinfo.z80
« Last Edit: Today at 04:45:03 am by the_mad_joob »
"No human is trustworthy, not even me..." - the_mad_joob

Offline E37

  • LV5 Advanced (Next: 300)
  • *****
  • Posts: 255
  • Rating: +17/-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: 302
  • Rating: +45/-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.
"No human is trustworthy, not even me..." - the_mad_joob

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: 4557
  • Rating: +716/-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: 302
  • Rating: +45/-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.
"No human is trustworthy, not even me..." - the_mad_joob

Offline the_mad_joob

  • LV6 Super Member (Next: 500)
  • ******
  • Posts: 302
  • Rating: +45/-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 »
"No human is trustworthy, not even me..." - the_mad_joob

Offline the_mad_joob

  • LV6 Super Member (Next: 500)
  • ******
  • Posts: 302
  • Rating: +45/-0
    • View Profile
Re: [8X+] [B&W] universal snacks
« Reply #7 on: Today at 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.
"No human is trustworthy, not even me..." - the_mad_joob