Author Topic: Screen Horizontal Line Count(er) and Disk files from basic.  (Read 1165 times)

0 Members and 1 Guest are viewing this topic.

Offline RobertM

  • CPC664
  • ***
  • Posts: 132
  • Country: au
  • CPC6128
  • Liked: 14
  • Likes Given: 0
Hi, I was almost going to ask this question in 'Hardware' but them I realized it's more a firmware question.

I want to keep or read a count of the horizontal screen line so that I change the screen mode after a specific line number.

I was hoping the firmware already keeps this number somewhere.

I want to have a play with ot in Basic before I go to the trouble of setting up for Asm.

The other question was about file editing (read/writing) fro basic. Can this be done to make files that are like memory loads with a start address and an entry address?

Ie does BASIC support random access / sequential access and can I write values of the typ BYTE in some way - like whiting CHR perhaps ???

Also is there a compete Port Map (like a Memory Map) so that I can see what ports I can use for a serial port so that I can transfer data from a normal PC or laptop.

And while I am here lol how do you guys develop code ona PC and transfer it to a live CPC6128????

I looked at the X-MASS and I was ready to buy when I learnt that I need all these extras like extended ROM and a backplane as well as the X_MASS. My currency is not doing well against the Euro so I will have to save a bit first or find another solution.

Surely there is something simple. Can I use the tape port and a MP3 player or something.

I can do electronics and write VHDL so I can make a PCB (single sided) with ROM etc and use CPLD to map it into the extended addressing space but I have no clue what the roms do there are so many of them.

Online andycadley

  • Supporter
  • 6128 Plus
  • *
  • Posts: 928
  • Liked: 458
  • Likes Given: 73
The CPC doesn't have a hardware method for detecting what screen line is being drawn, so you have to count interrupts (having determined which is the first via frame flyback) and then fine tune the position by delaying for a specific number of cycles. It's not something you can do from BASIC, you'd have to be doing it from machine code. The Plus machines are slightly nicer in this regard by allowing you to replace the normal interrupts with one at the start of a specific scanline, but it's not something exposed to BASIC at all.

Neither BASIC nor the firmware have any sort of random access to files on disk (having clearly been designed around cassettes) which is one of the few really lacking areas on the CPC I find. You're basically stuck with serial access via OPENOUT/WRITE/CLOSEOUT.

For development, I typically use an emulator for the most part (it's quicker and less cumbersome) then transfer the result either via SD Card using either an HxC Disk Drive or a C4CPC cartridge, depending on what I'm trying to do.

For I/O port, I think I/O Port Summary - CPCWiki probably covers it.

Offline RobertM

  • CPC664
  • ***
  • Posts: 132
  • Country: au
  • CPC6128
  • Liked: 14
  • Likes Given: 0
OK, so is it Non Maskable Interrupt (NMI) is generated with each HSYNC or at the beginning/end of each line????

I found that YSYNC goes to the 8255 and can be read from there. Is the video interrupt a vector in the jump table that I can change???


Offline arnoldemu

  • Supporter
  • 6128 Plus
  • *
  • Posts: 5.336
  • Country: gb
    • Unofficial Amstrad WWW Resource
  • Liked: 2278
  • Likes Given: 3478
OK, so is it Non Maskable Interrupt (NMI) is generated with each HSYNC or at the beginning/end of each line? ???

I found that YSYNC goes to the 8255 and can be read from there. Is the video interrupt a vector in the jump table that I can change???
No not on CPC. Yes on Plus.

On CPC, there are normally 6 interrupts per screen. One is synchronised with the vsync. The rest are 52 lines apart.
To get to a specific line you use one of the interrupts to get close then burn cycles to that line.

So it is best if you can position your changes when the interrupt happens to avoid burning cycles.

On the plus you can program which line to interrupt on.

Using interrupts precisly and burning cycles doesn't work too well with the firmware. It's possible but it's actually simpler if you go direct to the hardware and ignore the firmware.

That being said, there are some good examples on my website:

Unofficial Amstrad WWW Resource

Look in "source".


files: Yes you can load and save binary files and define their start, execution and length.

random access: No. You can read a file byte by byte using firmware but it must be from the start.

i/o port: There is no serial on cpc. You need extra hardware to do this, such as a Minibooster.

transfer to pc:

First is a audio cable into the cpc6128. I write my program on the pc, turn it into a "CDT" then an audio wave from that and play it into the CPC. Yes you can use the tape port and mp3! :)

2cdt will make a cdt file from binary file. playtzx will convert to au. audacity will play it. Now you need the cable :)

You could write a rom, it's not that bad. Look on Unofficial Amstrad WWW Resource for the soft968 and soft158 manuals.



My games. My Games
My website with coding examples: Unofficial Amstrad WWW Resource

Offline RobertM

  • CPC664
  • ***
  • Posts: 132
  • Country: au
  • CPC6128
  • Liked: 14
  • Likes Given: 0
Wow - you really know your stuff!!

The 52 lines is burning my head :( Hmm (6.5 blocks of 8) or (3.25 blocks of 16) - or 4 blocks of a nice prime number '13'.

I took a look at your web site and many of the inks are a different color - meaning I have already visited / downloaded them - probably via google.

I have a three week wait now for parts to make some hardware. I will play with the emulator for now.

Offline PulkoMandy

  • 464 Plus
  • *****
  • Posts: 410
  • Country: fr
  • Liked: 334
  • Likes Given: 3
The 52 lines is to get an interrupt at 300Hz. This is 6 interrupts per screen on 50Hz, and 5 interrupts per screen on 60Hz displays.
Note that you can reset the counter by writing to a gate array register, so it can act as a "wake me up in 52 lines" interrupt. Once set properly, you can use it this way for syncing stuff on the screen.

Offline AMSDOS

  • Supporter
  • 6128 Plus
  • *
  • Posts: 3.939
  • Country: au
    • index.php?action=treasury
    • Programs for Turbo Pascal 3
  • Liked: 1157
  • Likes Given: 1924
Unfortunately this topic is way out of my league, though regarding the Random Disc Access, I found this article from an old Popular Computing Weekly, which comes with BASIC program to setup M/C RSX & Demonstration Program & Part 2 of the Article includes ASM of the routine should you want to modify it.


Click on the Manual or here to view the Images.


Hope it helps.
* Using the old Amstrad Languages :D   * with the Firmware :P
* I also like to problem solve code in BASIC :)   * And type-in Type-Ins! :D

Home Computing Weekly Programs
Popular Computing Weekly Programs
Your Computer Programs
Updated Other Program Links on Profile Page (Update April 16/15 phew!)
Programs for Turbo Pascal 3