English Amiga Board


Go Back   English Amiga Board > Coders > Coders. General

 
 
Thread Tools
Old 29 July 2019, 19:10   #1
jarre
Registered User

jarre's Avatar
 
Join Date: Sep 2016
Location: Deventer - Netherlands
Posts: 599
Bootblock

Which program is the best to write a binary to the bootblock, and is instant werking, include boot checksum etc etc....
jarre is offline  
Old 29 July 2019, 22:51   #2
phx
Natteravn

phx's Avatar
 
Join Date: Nov 2009
Location: Herford / Germany
Posts: 2,031
What is your goal? Do you have a specific boot block which you want to write once to a disk, or do want to write a boot block, or even a whole ADF, as an automated part of a build process?

There may be tools for the first case. You can also write blocks to disk with AsmOne, for example.

For both cases it might be best to write a small, portable C program to perform that task. So you can even use it on other architectures, in case you are cross-developing, and include it in a Makefile.

When I am building an ADF for one of my games, I have one source which contains the whole disk, starting with the boot block and using INCBIN to include the remaining disk contents (for a trackloader).

Then I have a portable C tool which takes this image, pads it to 880K with zeros and calculates the boot block checksum. The result is a working ADF. Maybe this helps:
Code:
/*
 * Makes a disk image of 901120 (0xdc000) bytes.
 * Calculates boot block checksum.
 */

#include <stdio.h>
#include <string.h>
#include <stdint.h>

#define DISKSIZE (0xdc000)

uint8_t image[DISKSIZE];


static void boot_chksum(uint8_t *p)
{
  uint32_t oldchk,chk=0;
  int i;

  memset(p+4,0,4);
  for (i=0; i<1024; i+=4) {
    oldchk = chk;
    chk += ((uint32_t)p[i+0] << 24) | ((uint32_t)p[i+1] << 16) |
           ((uint32_t)p[i+2] << 8) | p[i+3];
    if (chk < oldchk)
      ++chk;  /* carry */
  }

  chk = ~chk;
  p[4] = (uint8_t)((chk >> 24) & 0xff);
  p[5] = (uint8_t)((chk >> 16) & 0xff);
  p[6] = (uint8_t)((chk >> 8) & 0xff);
  p[7] = (uint8_t)(chk & 0xff);
}


int main(int argc,char *argv[])
{
  FILE *f;
  int rc = 1;
  size_t len;

  if (argc == 2) {
    if (f = fopen(argv[1],"rb")) {
      len = fread(image,1,DISKSIZE,f);
      if (len > 0) {
        if (len < DISKSIZE)
          memset(image+len,0,DISKSIZE-len);
        boot_chksum(image);
        fwrite(image,1,DISKSIZE,stdout);
        rc = 0;
      }
      else
        fprintf(stderr,"Image read error!\n");
    }
    else
      fprintf(stderr,"Cannot open '%s'!\n",argv[1]);  
  }
  else
    fprintf(stderr,"Usage: %s <image data>\n",argv[0]);

  return rc;
}
phx 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
Writing a non-bootblock mcgeezer support.Apps 7 22 February 2019 00:50
Bootblock Games Dan support.Games 3 18 January 2018 17:14
bootblock mai support.Apps 7 25 September 2012 12:28
Anyone like to help understanding this bootblock ??? Joe Maroni Coders. Tutorials 2 15 February 2007 18:33
Bootblock checksum -Rob- Coders. General 5 17 April 2006 16:49

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 00:41.


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