Newbie questions: Programming tools and graphics

Discuss all aspects of programming here. From 8-bit through to modern architectures.
Post Reply
User avatar
robcfg
Posts: 10
Joined: Sun Dec 30, 2018 6:23 pm
Contact:

Newbie questions: Programming tools and graphics

Post by robcfg » Fri Jan 11, 2019 8:19 am

Hello everyone!

I'd like to make some programming for the Beeb/Electron and would like to know which tools do you guys use for that, how do I load machine code programs, and also how do I access individual pixels in Mode 1 as the memory organisation is quite peculiar.

Thanks in advance!

RobC
Posts: 2409
Joined: Sat Sep 01, 2007 9:41 pm
Contact:

Re: Newbie questions: Programming tools and graphics

Post by RobC » Fri Jan 11, 2019 10:45 am

For assembly language programming on modern hardware, I think most people tend to use BeebAsm as it'll generate an SSD file that you can load into an emulator.

You'll probably want to know where in memory you can put your code and data - this is a good and comprehensive guide but there's also some useful info in the Advanced User Guide (AUG). This book by Ian Birnbaum was also highly regarded BITD.

The AUG also shows the layout of screen memory in the various modes. For mode 1, each byte of screen memory maps to 4 pixels with bits 7 & 3 controlling the logical colour of the left-most pixel, bits 6 & 2 the next pixel etc. with bits 4 and 0 controlling the colour of the right-most pixel.

So, to only alter an individual pixel, you have to:
a) Read the appropriate byte of screen memory
b) Mask off the bits corresponding to the pixels you aren't changing (e.g. with an AND)
c) Write the bits corresponding to the pixel you are changing (e.g. with an OR)
d) Write the byte back to screen memory

There are lots of shortcuts if you don't care about what was on the screen previously or if you are setting multiple pixels but this is the general case.

Calculating the correct screen memory address is also a bit of a pain. There's a discussion and some example code here. You can make things a bit simpler by manipulating the CRTC registers to reduce the screen width - if that's something you want to do then I can dig out some example code.

User avatar
tricky
Posts: 3093
Joined: Tue Jun 21, 2011 8:25 am
Contact:

Re: Newbie questions: Programming tools and graphics

Post by tricky » Fri Jan 11, 2019 5:09 pm

beebasm has a sample program that I think prints dots on a rotating sphere, by plotting single dots in MODE 1, or a reshaped version of it.
You might also find some useful stuff on http://www.retrosoftware.co.uk which used to be the programming section of *.
Try the wiki or maybe search the forum.

User avatar
robcfg
Posts: 10
Joined: Sun Dec 30, 2018 6:23 pm
Contact:

Re: Newbie questions: Programming tools and graphics

Post by robcfg » Sat Jan 12, 2019 4:36 pm

Thanks for the nice tips!

Seems like I have a lot to read... :mrgreen:

Regarding the CRTC, if you set the screen to a Spectrum-like resolution (256x192), would the memory organization be the same as with a regular mode 1?

Thanks a bunch!

User avatar
tricky
Posts: 3093
Joined: Tue Jun 21, 2011 8:25 am
Contact:

Re: Newbie questions: Programming tools and graphics

Post by tricky » Sat Jan 12, 2019 5:37 pm

Yes, apart from it would be two pages per character row, making pixel X,Y to screen address:

Code: Select all

;; assumes screen starts at &4000, makes things easier (or instead of clc : adc)
addr = &70
.plot_pixel ;; X,Y in pixels
tya : lsr A : lsr A : lsr A : lsr A : ora #HI(scr DIV 2) : sta addr+1 ;; half addr offset
txa : and #&F4 : asl A : sta addr : rol addr+1 ;; shift top bit back into HI doubling it
tya : and #7 : tay ;; could or it into LO to not corrupt Y
txa : and #3 : tax : lda pixels,x : sta (addr),y ;; or maybe eor (addr),y : sta (addr),y
RTS
.pixels : EQUB &88, &44, &22, &11 ;; white
You can start the display anywhere (8 byte aligned) in the lower 32K, but &4000 makes some things a little easier or cheaper. Most of my games use MODE 1 256x256, even if some of it is "hidden" with 6845 trickery.
Last edited by tricky on Sat Jan 12, 2019 5:39 pm, edited 1 time in total.

VectorEyes
Posts: 179
Joined: Fri Apr 13, 2018 1:48 pm
Contact:

Re: Newbie questions: Programming tools and graphics

Post by VectorEyes » Sat Jan 12, 2019 10:45 pm

tricky wrote:
Fri Jan 11, 2019 5:09 pm
beebasm has a sample program that I think prints dots on a rotating sphere, by plotting single dots in MODE 1, or a reshaped version of it.
You might also find some useful stuff on http://www.retrosoftware.co.uk which used to be the programming section of *.
Try the wiki or maybe search the forum.
I could be wrong but I think that rotating sphere demo uses a 'square' Mode 2 (128x256).

(It's still a good place to start with learning Beeb coding though!)

User avatar
tricky
Posts: 3093
Joined: Tue Jun 21, 2011 8:25 am
Contact:

Re: Newbie questions: Programming tools and graphics

Post by tricky » Sun Jan 13, 2019 12:29 am

Your probably right, still same addressing 0, 1 or 2 until you choose the colour/pixel within the byte.
Also, I don't remember if it is "simple"!
Last edited by tricky on Sun Jan 13, 2019 12:29 am, edited 1 time in total.

User avatar
richardtoohey
Posts: 3663
Joined: Thu Dec 29, 2011 5:13 am
Location: Tauranga, New Zealand
Contact:

Re: Newbie questions: Programming tools and graphics

Post by richardtoohey » Mon Jan 21, 2019 8:58 am

Don't forget the fantastic resource in the old magazines like Beebug and The Micro User - lots of great articles in those.

Post Reply