Showing posts with label example. Show all posts
Showing posts with label example. Show all posts

Saturday, 4 April 2015

68k Part 1 - Easy now, raster lines and mouse buttons

Starting really simple now, lets change the colour of the raster lines and check the mouse buttons...

Changing the default colours on the Amiga

Yes there will be a heavy influence from the ScoopexUs 'Amiga Hardware Programming' tutorials on YouTube for the next few blog posts for sure. How can there not be? they are just so good!

I'm only learning, just a 68k noob!

I'm just trying to mess around with my own sections of code, for my own sanity, checking that I do sort of understand and hopefully will stick in my head for a while!  I will try to comment my code the best I can so that it explains itself.  Please PLEASE suggest better ways to do stuff, my samples sure wont be perfect.

My first snippet

Create a new file in Asm-One and copy paste the following code (or download source here).

This simple sample changes the default background and foreground colours, if the right mouse button is pressed down, it will change the colours whilst it's being pressed.  If the left mouse button is pressed the program is ended.

loop:
 
 btst #10, $dff016 ; test RIGHT mouse click
 bne default

; colours when right click is pressed
 
 move.w #$0f0, $dff180 ; moving colour in to background colour
 move.w #$0ff, $dff182 ; moving colour in to foreground colour

 bra  checkExit
 
default:

; default colours

 move.w #$f00, $dff180 ; moving colour in to background colour
 move.w #$ff0, $dff182 ; moving colour in to foreground colour 
 
checkExit:

 btst #6, $bfe001  ; test LEFT mouse click
 bne loop

 rts 

So I'm updating the colours every frame, I probably only need to do it at the start of the first raster line for each frame, but just as a sample I think it's ok.

Comment here or get involved on twitter: @rich_lloyd

Tuesday, 25 June 2013

Easy68k... Editor / Assembler / Simulator... 68k in Windows!

I have stumbled upon Easy68k, this looks like a great way to learn vanilla 68000 assembly language.  OK so it's in Windows, but surely I'll learn the skills needed for achieving my goal of making a game for the Amiga 500.

For starters it was very easy to install and it comes with some tutorials as well as examples on their website.  The forum on their website is full of people in a similar boat of learning 68000.

So already I've been reading up and now finally have a good environment to have a play about.  I will try and share with you examples of my progress and I think this is a good starting point.

Moving a red blob!

I often find with tutorials and examples when learning technology that the basic stuff is REALLY basic, then all of a sudden the examples are so advance you struggle working out the steps involved.  With that in mind, I wanted to share an example to move a blob about the screen using some user input, the keyboard.  This covers drawing to the screen, and capturing key strokes.  

There is already a Snake type game called Pallet Eater in the examples which is great, but I just wanted to break a few things down.  Simply draw a single red square, and the user can move up / down / left / right.  That's it!


That really is it!

I'm not an expert at assembly (yet), please let me know how I can improve my code.  Any sort of hints and tips would be great. Also if there is a better way to share the code examples please let me know as the code will be getting a lot bigger!

Comment here or get involved on twitter: @rich_lloyd

Here's the code:

*-----------------------------------------------------------
* Title      : Red Blob
* Written by : Rich (http://www.retrorich.co.uk)
* Date       : 24 June 2013
* Description: Moving a red blob around the screen using keys 4,6,8,5
*-----------------------------------------------------------

CR      EQU     $0D
LF      EQU     $0A 

START   ORG    $1000

* --  Make the pen and fill red  -- 
        move.l #$000000FF,d1 
     move.b #80,d0
     trap #15
     move.l #$000000FF,d1
     move.b #81,d0
     trap #15
      
* --  Turn echo off  --
     move.b #0,d1
     move.b #12,d0
     trap #15

* --  Get the time and store it in d5
     move.b #8,d0       
     trap #15
     move.l d1,d5    
   
* --  Set game loop speed
     move.l #5,speed    

* --  Set start position --     
     lea     player,a0     
     move.w #100,(a0)+     Set the start pos to be 100, 100
     move.w #100,(a0) 
        lea     player,a0
        
* -----------------------------------

LOOP    

* -- timing the game loop --

     move.b #8,d0     Re-get the time
     trap #15
     sub.l d5,d1     Subtract the old time from this new time
     cmp.l speed,d1 If less than  hundredths of a second has passed
     blo     LOOP         Loop again until it has
     move.b #8,d0     Now that enough time has passed
     trap #15
     move.l d1,d5     Put the current time in memory for the next loop

* -- grab input --
    *Check to see if a key has been pressed
     clr.l d1
     move.b #7,d0
     trap #15
     tst.l d1
     beq     nokey     Key wasn't pressed, clear movement

    *Read the key that was pressed and find out which key it was
     move.b #5,d0
     trap #15
     
     cmp.b #$35,d1     Key pressed: 5 (down)
     beq     move_down
     cmp.b #$38,d1     Key pressed: 8 (up)
     beq     move_up
     cmp.b #$34,d1     Key pressed: 4 (left)
     beq     move_left
     cmp.b #$36,d1     Key pressed: 6 (right)
     beq     move_right


nokey
        clr.l   d6          Clear any movement
        clr.l   d7
        
continue

        move.b  #11,d0      Clear screen
        move.w  #$ff00,d1
        trap    #15
    
     lea     player,a0     Store current position
     add.w d6,(a0)+     Add any movement to position
     add.w d7,(a0) 
        lea     player,a0       Update current position

        bsr     draw_square     Draw player

        bra     LOOP

* -- key(5) was pressed
move_down
     move.w #0,d6 
     move.w #10,d7 
     bra continue

* -- key(8) was pressed
move_up
     move.w #0,d6
     move.w #-10,d7
     bra continue

* -- key(4) was pressed
move_left
     move.w #-10,d6
     move.w #0,d7
     bra continue

* -- key(6) was pressed
move_right
     move.w #10,d6
     move.w #0,d7
     bra continue

DONE    MOVE.B  #9,D0
        TRAP    #15
    
draw_square
     clr.l d1
     clr.l d2
     clr.l d3
     clr.l d4
     move.w (a0)+,d1
     move.w (a0),d2
     move.w d1,d3
     add.w #10,d3
     move.w d2,d4
     add.w #10,d4
     move.b #87,d0
     trap #15
     rts
 
speed ds.l 1       store game loop speed
player ds.w 2       store player screen pos