Author Topic: 128k spectrum basic editor problems.  (Read 9716 times)

0 Members and 1 Guest are viewing this topic.

Offline ninogenio

  • Pentium
  • *****
  • Posts: 1668
  • Karma: 133
    • View Profile
128k spectrum basic editor problems.
« on: November 18, 2010 »
hey every one im making a chess game on the specci.

but i ran out of udg space, so i tryed to copy all the character set out of rom and into ram. and point the chars system variable to it but my editor goes haywire either displaying no charactors or they are a jumbled mess.

the funny thing is while the editor is messed up if i do print "nino" it writes nino fine. also if i edit the new character space with my own graphic that displayes fine to.

the code works perfect in 48K mode. so im guessing the 128k editor reads chars diffrent from print or the 48k editor. but i wondered if anyone knew how so i could fix this anoying problem.

i know i can point chars to new space at run time and swap it back at close but its a bit of a pain.

here is the code im using.
Code: [Select]
10 let ramtop=peek 23730+256*peek 237231
20 clear ramtop-768
30 let ramtop=peek 23730+256*peek 23731
40 for a=1 to 768
50 poke ramtop+a,peek (15615+a)
60 next a
70 chars=ramtop+1-256
80 poke 23606,chars-256*int(chars/256)
90 poke 23607,int(cars/256)

cheers for any help.
Challenge Trophies Won:

Offline Jim

  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 5301
  • Karma: 402
    • View Profile
Re: 128k spectrum basic editor problems.
« Reply #1 on: November 18, 2010 »
A couple of guesses...
On the 128k is the original char set still at 15615?
Second, the 128k has 2 roms, one for the new editor and other stuff, one for the main rom.  Is the correct rom paged in when you are reading the char set?
If not, you'll probably need a bit of asm to grab it.
Jim
Challenge Trophies Won:

Offline ninogenio

  • Pentium
  • *****
  • Posts: 1668
  • Karma: 133
    • View Profile
Re: 128k spectrum basic editor problems.
« Reply #2 on: November 18, 2010 »
ahh i think your right jim.

the char  variable still points at 15615-32 in 128k but you might be right about the which rom is paged in.

what was throwing me is that after i try that code if i had to say alter the normal letter a to a space invader.

and do print "im a space invader"

even though the editor is garbled it would write the sentence perfect with two invaders in place of the a's.

so there must be letters getting copyed to the new ram space but the interpreter isnt reading them correctly.

ill have a play around and check to see if the characters are there in rom as expected and if not try paging cheers.
Challenge Trophies Won:

Offline ninogenio

  • Pentium
  • *****
  • Posts: 1668
  • Karma: 133
    • View Profile
Re: 128k spectrum basic editor problems.
« Reply #3 on: November 18, 2010 »
i managed to recreate the error on the spin emulator. im guessing i have to page rom 1 in read the character data in and then switch bach to rom 0 128k editor. iv attached a pic of the messy screen.

heres the data of which rom is used at the time of messy editor.

Computer Model:
   Sinclair ZX Spectrum +2
 
Timing Information:
   T-States per frame:    70908
   T-States per Scanline: 228
   Contention:
      128k Contention Timing
 
ROM Information:
   ROM Filename: plus2.rom
   ROM Size: 32Kb
   ROM Paged: 0 (128k Editor)
 
RAM Paging Information:
   $0000..$3FFF: ROM 0 (128k Editor)
   $4000..$7FFF: Page 5
   $8000..$BFFF: Page 2
   $C000..$FFFF: Page 7
   Screen is mapped to Page 5
   Paging is Enabled

and here is the pic.

edit i just tryed this bit of code.

Code: [Select]
LD      A,(0x5b5c)      ;Previous value of port
AND     0xf8
OR      4               ;Select bank 4
LD      BC,0x7ffd
DI
LD      (0x5b5c),A
OUT     (C),A

i think it works but switches the system to 48k mode im just wondering if switching the system back to 128k rom 0 from 48k will proserve the ram and if not is there a way to page the rom into a free ram bank so that i can work on it without it being executed. cheers.
« Last Edit: November 19, 2010 by ninogenio »
Challenge Trophies Won:

Offline Jim

  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 5301
  • Karma: 402
    • View Profile
Re: 128k spectrum basic editor problems.
« Reply #4 on: November 19, 2010 »
I guess you're working from here
http://www.worldofspectrum.org/faq/reference/128kreference.htm
The sample code (the code you pasted) shows how to map a different 16Kb RAM bank into the top 16Kb of the 64Kb memory map, which isn't what you want.  Also you missed the EI off the end.  DI and EI are disable/enable interrupts.  You don't want to leave them disabled!  When interrupts are enabled though, bits of spectrum rom are executing all the time and they do not expect you to change which roms are paged in without telling it.
Probably also, your stack is in the top 16Kb of memory, and moving it away is probably bad :P

Anyway, the ROM select is controlled by bit 4 of that port

select ROM 0
Code: [Select]
LD      A,(0x5b5c)      ;Previous value of port
AND     0xef              ;set bit 4 to 0
LD      BC,0x7ffd
DI
LD      (0x5b5c),A
OUT     (C),A
EI

select ROM 1
Code: [Select]
LD      A,(0x5b5c)      ;Previous value of port
OR      16              ;set bit 4 to 1
LD      BC,0x7ffd
DI
LD      (0x5b5c),A
OUT     (C),A
EI

It's cool that the emulator behaves the same way :)

Note that, if you leave interrupts disabled while you copy the ROM data, you don't have to worry about keeping 5b5c up-to-date
Code: [Select]
LD      A,(0x5b5c)      ;Previous value of port
OR      16              ;set bit 4 to 1 (page in ROM1)
LD      BC,0x7ffd
DI
OUT     (C),A

... copy the char set

LD      BC,0x7ffd
LD      A,(0x5b5c)      ;Previous value of port
OUT     (C),A
EI

Jim
« Last Edit: November 19, 2010 by Jim »
Challenge Trophies Won:

Offline ninogenio

  • Pentium
  • *****
  • Posts: 1668
  • Karma: 133
    • View Profile
Re: 128k spectrum basic editor problems.
« Reply #5 on: November 20, 2010 »
ahh cheers for that jim k+, when i pasted that code across i got confused about what it was doing but youve cleared it all up.

i tryed out your code on my specci in my assembler and it works a treat. it does its thing and drops out with the computer none the wiser as to whats went on.

now i just need to get my char converted to asm im sort of 60% of the way there.

can i ask in asm when converting addresses from basic does it go like this.

in basic
80 poke 23606,chars-256*int(chars/256)
90 poke 23607,int(cars/256)
this makes one address lo/hi byte

but in asm is it possible to just do this.
LD      (23606),ramtop-32

would that load chars 606 and 607 with the high and lo bytes without the hastle you have to go through in basic.
Challenge Trophies Won:

Offline Jim

  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 5301
  • Karma: 402
    • View Profile
Re: 128k spectrum basic editor problems.
« Reply #6 on: November 20, 2010 »
Yes, you can load 2 bytes at a time into a register pair in asm.
ld de,(23606)

Your code is going to be
Code: [Select]
ld bc,768
ld hl,source address
ld de,destination address
ldir

Jim
Challenge Trophies Won:

Offline ninogenio

  • Pentium
  • *****
  • Posts: 1668
  • Karma: 133
    • View Profile
Re: 128k spectrum basic editor problems.
« Reply #7 on: November 21, 2010 »
aw cheers jim, heres what iv been trying.
all i get now though is garbled characters on the editor but now even when i do print "nino" or something thats garbled too so something has changed.

Code: [Select]
BASIC
10 CLEAR 64367
20 LOAD "romswitch" CODE 65167,33
30 LET ramtop=PEEK 23730+256*PEEK 23731
40 RANDOMIZE USR 65167
50 LET chars=ramtop+1-256
60 POKE 23606,chars-256*INT(chars/256)
70 POKE 23607,INT(chars/256)

"romswitch"
ORG 65167
LD A,(0x5b5c)
OR 16
LD BC,0x7ffd
DI
OUT (C),A
LD BC,768
LD HL,(15615)
LD DE,(23730)
LDIR
LD BC,0x7ffd
LD A,(0x5b5c)
OUT (C),A
EI
RET

« Last Edit: November 22, 2010 by ninogenio »
Challenge Trophies Won:

Offline Jim

  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 5301
  • Karma: 402
    • View Profile
Re: 128k spectrum basic editor problems.
« Reply #8 on: November 22, 2010 »
LD HL,(15615)
should be
LD HL,15615

You want the address to be 15615, not the value of the 2 bytes at that location.

Jim
Challenge Trophies Won:

Offline ninogenio

  • Pentium
  • *****
  • Posts: 1668
  • Karma: 133
    • View Profile
Re: 128k spectrum basic editor problems.
« Reply #9 on: November 22, 2010 »
aw of course :) cheers jim.

i had to do pushes and pops for af bc hl and de around the ldir also as basic was throwing up an error.

it still doesnt work its either that chars is miss aligned or that im still not copying across the proper data. im just looking at the complete rom dissasembly over at wos to see what i can come up with.
Challenge Trophies Won:

Offline Jim

  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 5301
  • Karma: 402
    • View Profile
Re: 128k spectrum basic editor problems.
« Reply #10 on: November 22, 2010 »
Yes, you might need to push/pop some registers to keep BASIC happy - you can do that round the outside of the whole routine.

Check this line
LET chars=ramtop+1-256
Your original code used a FOR loop that went from 1 to 768.  The asm code goes from 0.  I think the +1 is not needed.
Also, I just checked, chars is 0x3d00 (15616) not 15615.

The misalignment is almost certainly down to a series of off-by-1 problems.

Jim
Challenge Trophies Won:

Offline ninogenio

  • Pentium
  • *****
  • Posts: 1668
  • Karma: 133
    • View Profile
Re: 128k spectrum basic editor problems.
« Reply #11 on: November 23, 2010 »
ah i can see that, when looking at rom 0 dissasembled,

thanks for all your help, but i just cant get this going right now. i checked and the character set is being copyed properly i used peeks to print the characters on screen. a therory i have now is that possably the 128k editor is doing something a bit diffrent possably using the chars variable diffrenent as well as paging and when changing chars to a different location even though there is proper data there its messing the editor up.

i think i will just change chars at run time so it still gives me the extended udg just now and maybe later when i get more familiar with the roms ill come back to this. thanks though jim i have learned loads from this little exercise.
« Last Edit: November 23, 2010 by ninogenio »
Challenge Trophies Won:

Offline Jim

  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 5301
  • Karma: 402
    • View Profile
Re: 128k spectrum basic editor problems.
« Reply #12 on: November 24, 2010 »
You'll have to remind me what you want the code to do, what it is currently doing, and what is wrong with that :)

Jim
Challenge Trophies Won:

Offline ninogenio

  • Pentium
  • *****
  • Posts: 1668
  • Karma: 133
    • View Profile
Re: 128k spectrum basic editor problems.
« Reply #13 on: November 24, 2010 »
np jim,

i wanted the code to copy the char set up too ram so i could play around and have a huge udg to play around with.

currently it does this perfectly in 128k/48k but it 128k the editor gets messed up but in 48k it doesnt.

the funny thing is that in 128k its only the editor chars that gets messed everything else is fine ie if i do print it prints my message ok from my new character set.

its not so much of a problem if i just switch the char variable at run time. i just like to try and understand whats going on when something isnt right.

btw using the asm routine for copying the char set is jawdropingly quick in comparison with basic :)
Challenge Trophies Won:

Offline ninogenio

  • Pentium
  • *****
  • Posts: 1668
  • Karma: 133
    • View Profile
Re: 128k spectrum basic editor problems.
« Reply #14 on: December 09, 2010 »
hey jim back on this again  :)

just wondering does the spectrum page the 2 roms in and out under 128k mode on a regular basis like when executing code etc. so that the 2 roms make one big operating system. as i have always thought of it as one rom was 48k mode and one was 128k but now looking at it that cant be, im now thinking the spectrum uses aspects from both roms in 128k mode and switches the roms in and out quite frequently to use various parts of them.

and when switching into proper 48k mode it switches the correct main rom in, locks the paging out as well as some other things and does an effective usr 0.

does that seem about right?

cheers
« Last Edit: December 09, 2010 by ninogenio »
Challenge Trophies Won:

Offline Jim

  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 5301
  • Karma: 402
    • View Profile
Re: 128k spectrum basic editor problems.
« Reply #15 on: December 09, 2010 »
Yes, I think it switches regularly, but I don't know for sure.  One ROM is mostly the original 48k spectrum ROM with a few changes (extra code/vars in what used to be the printer buffer) the other is the new BASIC editor.
While you're running BASIC programs you have no guarantee which ROM is paged in.

Jim
« Last Edit: December 09, 2010 by Jim »
Challenge Trophies Won:

Offline ninogenio

  • Pentium
  • *****
  • Posts: 1668
  • Karma: 133
    • View Profile
Re: 128k spectrum basic editor problems.
« Reply #16 on: December 09, 2010 »
cheers jim, the quirks of the 128k spectrum :)

its a very tricky system to get on top of but fun at the same time. im narrowing this down a bit i think, im starting to get the idea that the 128k editor shaddows the 48k char set into ram somewhere low down and uses charset_var+offest to get to the editor characters so when you change the charset_var thats why only the editor messes up but not print etc, thats just a bit of a guess right now and i still havent quite got any thing going. but hopefully will soon.



Challenge Trophies Won:

Offline Jim

  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 5301
  • Karma: 402
    • View Profile
Re: 128k spectrum basic editor problems.
« Reply #17 on: December 10, 2010 »
If it was going to copy them anywhere, you'd think it would use the editor scratch pad in bank 7.
But I looked for 'CHARS' in this excellent web site disassembly of ROM 0 and I don't see it changing CHARS anywhere.
http://www.matthew-wilson.net/spectrum/rom/PLUS2.html#L019D

Also, I found the 'list' command and it just calls the original 48K ROM 1 to do its printing.
http://www.matthew-wilson.net/spectrum/rom/PLUS2.html#L3B3F

Jim
Challenge Trophies Won:

Offline ninogenio

  • Pentium
  • *****
  • Posts: 1668
  • Karma: 133
    • View Profile
Re: 128k spectrum basic editor problems.
« Reply #18 on: December 10, 2010 »
excellent link there jim, thanks!

ill have too look over them a bit closer. another thing i forgot to mention is that when the editor is messed the interpretor messages like OK 0 or C nonsense in basic when code is run gets written fine so the editor must do something slightly diffrent.
Challenge Trophies Won: