English Amiga Board


Go Back   English Amiga Board > Coders > Coders. Language > Coders. Blitz Basic

 
 
Thread Tools
Old 24 March 2017, 09:25   #1
MickGyver
Registered User
 
MickGyver's Avatar
 
Join Date: Oct 2008
Location: Finland
Posts: 643
CD32 NVRam read/write example

Continuing my CD32 experimentations I made a simple NVRam read and write example. I have only tested this on WinUAE but should work on the real console, it uses the CD32 library by ACID.

Code:
; Test writing a savegame to CD32 NVRAM (based on code found with Acid CD32 library)
; Note: Only tested on WinUAE but I can't see why it wouldn't work on a real CD32
;
; The Acid CD32 library is needed for this example to work:
; http://www.david-mcminn.co.uk/blitz-2000/archives/libraries/acid.html
;
; Note to test on A1200 rem out cdmem commands and enable file commands
;
; Amiga or QAmiga mode is required when reading and saving NVRAM
;
; note to go to the bother of getting it working with ram:test b4
; replacing with cd32mem commands and also remember size in cd32mem
; command represents 10 bytes!
;
; I think also there is available nvmem type simulation library
; for 3.0 so you can test cd32mem commands properly on A1200

; Savegame structure
NEWTYPE .savegame
  name.b[11]        ; Character name, max 10 chars long + null char       11B
  stats.b[9]        ; Character stats (ex. 4 bit nibbles can store 0-15    9B
  flags.w[5]        ; Various game status flags (one per bit) 5*2 bytes   10B
  values.w[10]      ; Various values 2 bytes each (coordinates etc.)      20B
                    ;                                    Total (bytes):   50B
End NEWTYPE

; Create a savegame instance
DEFTYPE .savegame savegame

success = False
cd32 = False

; Variables used in game
name$ = ""
Dim stats.b(9)
Dim flags.w(5)
Dim values.w(10)

; Initialize
BLITZ                                   ; Go into blitz mode
Slice 0,44,320,200,$fff8,4,8,16,320,320 ; Create a slice
BitMap 0, 320, 200, 4                   ; Create a bitmap
Show 0                                  ; Show the bitmap in the slice
BitMapOutput 0                          ; Output print commands to bitmap 0
PalRGB 0,1,15,15,15                     ; Set colour index 1 to white
Use Palette 0                           ; Use palette must be called after changing the colors with PalRGB
Colour 1                                ; Set color index used for printing

; Amiga or QAmiga mode is required when reading and saving NVRAM
QAMIGA

cd32 = InitCD32 ; Initialize / check CD32

; ------------------------------------------------------------
; WRITE NVRAM ------------------------------------------------

; Give some dummy values to our game variables
name$ = "Daenerys"
For i=0 to 8
  stats(i) = i+1
Next
For i=0 to 4
  flags(i) = (i+1)*100
Next
For i=0 to 9
  values(i) = (i+1)*1000
Next

; Store our game variables in the newtype
Poke$ &savegame\name[0], Left$(name$,10) ; Use the ten first characters of name, 11th character should be 0 (null char)
For i=0 to 8
  savegame\stats[i] = stats(i)
Next
For i=0 to 4
  savegame\flags[i] = flags(i)
Next
For i=0 to 9
  savegame\values[i] = values(i)
Next

If cd32 = True
  success = WriteCD32Mem("STORMBORN", "SAVE", &savegame, 5)  ; Write savegame as 5*10 bytes
Else
  ; Write to RAM on other Amigas
  If WriteFile(0,"ram:test")
    WriteMem 0, &savegame, 50
    CloseFile 0
  EndIf
EndIf
; ------------------------------------------------------------

; ------------------------------------------------------------
; READ NVRAM -------------------------------------------------
If cd32 = True
  success = ReadCD32Mem("STORMBORN", "SAVE", &savegame, 5)  ; Reads 5*10 bytes to savegame
Else
  ; Read from RAM on other Amigas
  success = ReadFile(0,"ram:test") 
  If success = True
    ReadMem 0, &savegame, 50
    CloseFile 0
  EndIf
EndIf

If success = True
  ; Reads 11 bytes starting from the address of the first name byte array in the savegame
  name$ = Peeks$(&savegame\name[0],11) 
  ; Read the stats, flags and values
  For i=0 to 8
    stats(i) = savegame\stats[i]
  Next
  For i=0 to 4
    flags(i) = savegame\flags[i]
  Next
  For i=0 to 9
    values(i) = savegame\values[i]
  Next
EndIf
; ------------------------------------------------------------


Delay_ 20 ; I'm not sure if a delay is needed before going to Blitz mode, maybe not
BLITZ

; Print the name and a value to screen
Locate 0,0 : Print name$
Locate 0,1 : Print values(4)

Repeat
  ; Wait for a mouse / joystick button
Until (Joyb(1) > 0 OR Joyb(0) > 0)
MickGyver is offline  
Old 24 March 2017, 10:50   #2
earok
Registered User
 
Join Date: Dec 2013
Location: Auckland
Posts: 3,539
Great stuff, thanks for that
earok is offline  
Old 24 March 2017, 11:10   #3
Anakirob
Unregistered User
 
Anakirob's Avatar
 
Join Date: Nov 2005
Location: Tasmania
Age: 42
Posts: 893
Quote:
Originally Posted by earok View Post
Great stuff, thanks for that
I second that motion, and might add that I have been considering making a CD32 game for a while now and if I ever do get around to it then I will almost certainly be using this code. Thankyou.
Anakirob is offline  
 


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Similar Threads
Thread Thread Starter Forum Replies Last Post
Extend CD32 NVRAM? Amiga1992 Hardware mods 41 16 December 2018 14:59
CD32 NVRAM management Amiga1992 support.Hardware 9 20 February 2012 13:27
CD32 nvram file...? Christian support.WinUAE 11 13 December 2006 22:25
read but wont write Dave_wb support.Hardware 0 09 December 2006 14:04
Cd32 Nvram Phantomz request.Apps 5 16 March 2003 21:09

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 19:16.

Top

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Page generated in 0.11119 seconds with 13 queries